1#!/usr/bin/perl -w 2use strict; 3 4use Test::More; 5 6plan 'no_plan'; 7 8sub list_return { 9 return if @_; 10 return qw(foo bar baz); 11} 12 13sub 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 23sub list_mirror { 24 return undef if (@_ == 1 and not defined $_[0]); 25 return @_; 26 27} 28 29use Fatal qw(list_return); 30use Fatal qw(:void list_return2); 31 32TODO: { 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 44eval { 45 my @line = list_return(1); # Should die 46}; 47 48ok($@,"List return fatalised"); 49 50### Tests where we've fatalised our function with :void ### 51 52my @list2 = list_return2(); 53 54is_deeply(\@list2,[qw(foo bar baz)],'fatal sub works in list context'); 55 56eval { 57 my @line = list_return2(1); # Shouldn't die 58}; 59 60ok(! $@,"void List return fatalised survives when non-void"); 61 62eval { 63 list_return2(1); 64}; 65 66ok($@,"void List return fatalised"); 67