| 1 |
#!/usr/bin/perl -w |
| 2 |
use strict; |
| 3 |
|
| 4 |
use Test::More 'no_plan'; |
| 5 |
|
| 6 |
sub mytest { |
| 7 |
return $_[0]; |
| 8 |
} |
| 9 |
|
| 10 |
is(mytest(q{foo}),q{foo},"Mytest returns input"); |
| 11 |
|
| 12 |
my $return = eval { mytest(undef); }; |
| 13 |
|
| 14 |
ok(!defined($return), "mytest returns undef without autodie"); |
| 15 |
is($@,"","Mytest doesn't throw an exception without autodie"); |
| 16 |
|
| 17 |
$return = eval { |
| 18 |
use autodie qw(mytest); |
| 19 |
|
| 20 |
mytest('foo'); |
| 21 |
}; |
| 22 |
|
| 23 |
is($return,'foo',"Mytest returns input with autodie"); |
| 24 |
is($@,"","No error should be thrown"); |
| 25 |
|
| 26 |
$return = eval { |
| 27 |
use autodie qw(mytest); |
| 28 |
|
| 29 |
mytest(undef); |
| 30 |
}; |
| 31 |
|
| 32 |
isa_ok($@,'autodie::exception',"autodie mytest/undef throws exception"); |
| 33 |
|
| 34 |
# We set initial values here because we're expecting $data to be |
| 35 |
# changed to undef later on. Having it as undef to begin with means |
| 36 |
# we can't see mytest(undef) working correctly. |
| 37 |
|
| 38 |
my ($data, $data2) = (1,1); |
| 39 |
|
| 40 |
eval { |
| 41 |
use autodie qw(mytest); |
| 42 |
|
| 43 |
{ |
| 44 |
no autodie qw(mytest); |
| 45 |
|
| 46 |
$data = mytest(undef); |
| 47 |
$data2 = mytest('foo'); |
| 48 |
} |
| 49 |
}; |
| 50 |
|
| 51 |
is($@,"","no autodie can counter use autodie for user subs"); |
| 52 |
ok(!defined($data), "mytest(undef) should return undef"); |
| 53 |
is($data2, "foo", "mytest(foo) should return foo"); |
| 54 |
|
| 55 |
eval { |
| 56 |
mytest(undef); |
| 57 |
}; |
| 58 |
|
| 59 |
is($@,"","No lingering failure effects"); |
| 60 |
|
| 61 |
$return = eval { |
| 62 |
mytest("bar"); |
| 63 |
}; |
| 64 |
|
| 65 |
is($return,"bar","No lingering return effects"); |