Blame t/basic.t

Packit c9e8cb
#!perl -w
Packit c9e8cb
Packit c9e8cb
use Test::More tests => 32;
Packit c9e8cb
Packit c9e8cb
use_ok( Class::ReturnValue);
Packit c9e8cb
Packit c9e8cb
sub foo {
Packit c9e8cb
    my $r = Class::ReturnValue->new();
Packit c9e8cb
    $r->as_array('one', 'two',  'three');
Packit c9e8cb
   return $r->return_value();
Packit c9e8cb
   
Packit c9e8cb
   
Packit c9e8cb
   
Packit c9e8cb
}
Packit c9e8cb
Packit c9e8cb
my @array;
Packit c9e8cb
ok(@array = foo());
Packit c9e8cb
is($array[0] , 'one','dereferencing to an array is ok');
Packit c9e8cb
is($array[1] , 'two','dereferencing to an array is ok');
Packit c9e8cb
is($array[2] , 'three','dereferencing to an array is ok');
Packit c9e8cb
is($array[3] , undef ,'dereferencing to an array is ok');
Packit c9e8cb
Packit c9e8cb
ok(my $ref = foo());
Packit c9e8cb
ok(my @array2 = $ref->as_array());
Packit c9e8cb
is($array2[0] , 'one','dereferencing to an arrayref is ok');
Packit c9e8cb
Packit c9e8cb
is($array2[1] , 'two','dereferencing to an arrayref is ok');
Packit c9e8cb
is($array2[2] , 'three','dereferencing to an arrayref is ok');
Packit c9e8cb
is($array2[3] , undef ,'dereferencing to an arrayref is ok');
Packit c9e8cb
ok(foo(),"Foo returns true in a boolean context");
Packit c9e8cb
Packit c9e8cb
my ($a, $b, $c) = foo();
Packit c9e8cb
is ($a , 'one', "first element is 1");
Packit c9e8cb
is ($b, 'two' , "Second element is two");
Packit c9e8cb
is ($c , 'three', "Third element is three");
Packit c9e8cb
Packit c9e8cb
my ($a2, $b2, $c2) = foo();
Packit c9e8cb
is ($a2 , 'one', "first element is 1");
Packit c9e8cb
is ($b2, 'two' , "Second element is two");
Packit c9e8cb
is ($c2 , 'three', "Third element is three");
Packit c9e8cb
Packit c9e8cb
Packit c9e8cb
sub bing {
Packit c9e8cb
    my $ret = Class::ReturnValue->new();
Packit c9e8cb
    return $ret->return_value;
Packit c9e8cb
    return("Dead");
Packit c9e8cb
}
Packit c9e8cb
Packit c9e8cb
ok(bing());
Packit c9e8cb
ok(bing() ne 'Dead');
Packit c9e8cb
Packit c9e8cb
Packit c9e8cb
Packit c9e8cb
sub bar {
Packit c9e8cb
    my $retval3 = Class::ReturnValue->new();
Packit c9e8cb
    $retval3->as_array(1,'asq');
Packit c9e8cb
   return_value $retval3;
Packit c9e8cb
}
Packit c9e8cb
ok(bar());
Packit c9e8cb
sub baz {
Packit c9e8cb
    my $retval = Class::ReturnValue->new();
Packit c9e8cb
    $retval->as_error(errno=> 1);
Packit c9e8cb
   return_value  $retval;
Packit c9e8cb
}
Packit c9e8cb
Packit c9e8cb
if(baz()){
Packit c9e8cb
 ok (0,"returning an error evals as true");
Packit c9e8cb
} else {
Packit c9e8cb
 ok (1,"returning an error evals as false");
Packit c9e8cb
Packit c9e8cb
}
Packit c9e8cb
Packit c9e8cb
ok(my $retval = Class::ReturnValue->new());
Packit c9e8cb
ok($retval->as_error( errno => 20,
Packit c9e8cb
                        message => "You've been eited",
Packit c9e8cb
                        do_backtrace => 1));
Packit c9e8cb
like($retval->backtrace, qr{Trace begun at t[\\/]basic.t line});
Packit c9e8cb
is($retval->error_message,"You've been eited");
Packit c9e8cb
Packit c9e8cb
Packit c9e8cb
ok(my $retval2 = Class::ReturnValue->new());
Packit c9e8cb
ok($retval2->as_error( errno => 1,
Packit c9e8cb
                            message => "You've been eited",
Packit c9e8cb
                             do_backtrace => 0 ));
Packit c9e8cb
is($retval2->backtrace ,undef);
Packit c9e8cb
is($retval2->errno, 1, "Got the errno");
Packit c9e8cb
isnt($retval2->errno,20, "Errno knows that 20 != 1");
Packit c9e8cb
Packit c9e8cb
1;