1#!/usr/bin/perl -w
2use strict;
3
4use Test::More;
5
6plan '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
16sub 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
25eval {
26    list_mirror();
27};
28
29is($@, "", "No autodie, no fatality");
30
31eval {
32    use autodie qw(list_mirror);
33    list_mirror();
34};
35
36ok($@, "Autodie fatality for empty return in void context");
37
38eval {
39    list_mirror();
40};
41
42is($@, "", "No autodie, no fatality (after autodie used)");
43
44eval {
45    use autodie qw(list_mirror);
46    list_mirror(undef);
47};
48
49ok($@, "Autodie fatality for undef return in void context");
50
51eval {
52    use autodie qw(list_mirror);
53    my @list = list_mirror();
54};
55
56ok($@,"Autodie fatality for empty list return");
57
58eval {
59    use autodie qw(list_mirror);
60    my @list = list_mirror(undef);
61};
62
63ok($@,"Autodie fatality for undef list return");
64
65eval {
66    use autodie qw(list_mirror);
67    my @list = list_mirror("tada");
68};
69
70ok(! $@,"No Autodie fatality for defined list return");
71
72eval {
73    use autodie qw(list_mirror);
74    my $single = list_mirror("tada");
75};
76
77ok(! $@,"No Autodie fatality for defined scalar return");
78
79eval {
80    use autodie qw(list_mirror);
81    my $single = list_mirror(undef);
82};
83
84ok($@,"Autodie fatality for undefined scalar return");
85