Commit | Line | Data |
0b09a93a |
1 | #!/usr/bin/perl -w |
2 | use strict; |
3 | |
4 | use Test::More; |
5 | |
6 | plan 'no_plan'; |
7 | |
8 | sub list_return { |
9 | return if @_; |
10 | return qw(foo bar baz); |
11 | } |
12 | |
13 | sub list_return2 { |
14 | return if @_; |
15 | return qw(foo bar baz); |
16 | } |
17 | |
18 | # Returns a list presented to it, but also returns a single |
19 | # undef if given a list of a single undef. This mimics the |
20 | # behaviour of many user-defined subs and built-ins (eg: open) that |
21 | # always return undef regardless of context. |
22 | |
23 | sub list_mirror { |
24 | return undef if (@_ == 1 and not defined $_[0]); |
25 | return @_; |
26 | |
27 | } |
28 | |
29 | use Fatal qw(list_return); |
30 | use Fatal qw(:void list_return2); |
31 | |
32 | TODO: { |
33 | |
34 | # Clobbering context was documented as a bug in the original |
35 | # Fatal, so we'll still consider it a bug here. |
36 | |
37 | local $TODO = "Fatal clobbers context, just like it always has."; |
38 | |
39 | my @list = list_return(); |
40 | |
41 | is_deeply(\@list,[qw(foo bar baz)],'fatal sub works in list context'); |
42 | } |
43 | |
44 | eval { |
45 | my @line = list_return(1); # Should die |
46 | }; |
47 | |
48 | ok($@,"List return fatalised"); |
49 | |
50 | ### Tests where we've fatalised our function with :void ### |
51 | |
52 | my @list2 = list_return2(); |
53 | |
54 | is_deeply(\@list2,[qw(foo bar baz)],'fatal sub works in list context'); |
55 | |
56 | eval { |
57 | my @line = list_return2(1); # Shouldn't die |
58 | }; |
59 | |
60 | ok(! $@,"void List return fatalised survives when non-void"); |
61 | |
62 | eval { |
63 | list_return2(1); |
64 | }; |
65 | |
66 | ok($@,"void List return fatalised"); |