| 1 |
#!/usr/bin/perl -w |
| 2 |
use strict; |
| 3 |
|
| 4 |
use Test::More; |
| 5 |
|
| 6 |
plan 'no_plan'; |
| 7 |
|
| 8 |
# Returns a list presented to it, but also returns a single |
| 9 |
# undef if given a list of a single undef. This mimics the |
| 10 |
# behaviour of many user-defined subs and built-ins (eg: open) that |
| 11 |
# always return undef regardless of context. |
| 12 |
# |
| 13 |
# We also do an 'empty return' if no arguments are passed. This |
| 14 |
# mimics the PBP guideline for returning nothing. |
| 15 |
|
| 16 |
sub list_mirror { |
| 17 |
return undef if (@_ == 1 and not defined $_[0]); |
| 18 |
return if not @_; |
| 19 |
return @_; |
| 20 |
|
| 21 |
} |
| 22 |
|
| 23 |
### autodie clobbering tests ### |
| 24 |
|
| 25 |
eval { |
| 26 |
list_mirror(); |
| 27 |
}; |
| 28 |
|
| 29 |
is($@, "", "No autodie, no fatality"); |
| 30 |
|
| 31 |
eval { |
| 32 |
use autodie qw(list_mirror); |
| 33 |
list_mirror(); |
| 34 |
}; |
| 35 |
|
| 36 |
ok($@, "Autodie fatality for empty return in void context"); |
| 37 |
|
| 38 |
eval { |
| 39 |
list_mirror(); |
| 40 |
}; |
| 41 |
|
| 42 |
is($@, "", "No autodie, no fatality (after autodie used)"); |
| 43 |
|
| 44 |
eval { |
| 45 |
use autodie qw(list_mirror); |
| 46 |
list_mirror(undef); |
| 47 |
}; |
| 48 |
|
| 49 |
ok($@, "Autodie fatality for undef return in void context"); |
| 50 |
|
| 51 |
eval { |
| 52 |
use autodie qw(list_mirror); |
| 53 |
my @list = list_mirror(); |
| 54 |
}; |
| 55 |
|
| 56 |
ok($@,"Autodie fatality for empty list return"); |
| 57 |
|
| 58 |
eval { |
| 59 |
use autodie qw(list_mirror); |
| 60 |
my @list = list_mirror(undef); |
| 61 |
}; |
| 62 |
|
| 63 |
ok($@,"Autodie fatality for undef list return"); |
| 64 |
|
| 65 |
eval { |
| 66 |
use autodie qw(list_mirror); |
| 67 |
my @list = list_mirror("tada"); |
| 68 |
}; |
| 69 |
|
| 70 |
ok(! $@,"No Autodie fatality for defined list return"); |
| 71 |
|
| 72 |
eval { |
| 73 |
use autodie qw(list_mirror); |
| 74 |
my $single = list_mirror("tada"); |
| 75 |
}; |
| 76 |
|
| 77 |
ok(! $@,"No Autodie fatality for defined scalar return"); |
| 78 |
|
| 79 |
eval { |
| 80 |
use autodie qw(list_mirror); |
| 81 |
my $single = list_mirror(undef); |
| 82 |
}; |
| 83 |
|
| 84 |
ok($@,"Autodie fatality for undefined scalar return"); |