summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/perl/cpan/autodie/t/context_lexical.t
blob: ce50b75c4b98f21349a1b0be96078e07ce42b9df (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/perl -w
use strict;

use Test::More;

plan 'no_plan';

# Returns a list presented to it, but also returns a single
# undef if given a list of a single undef.  This mimics the
# behaviour of many user-defined subs and built-ins (eg: open) that
# always return undef regardless of context.
#
# We also do an 'empty return' if no arguments are passed.  This
# mimics the PBP guideline for returning nothing.

sub list_mirror {
    return undef if (@_ == 1 and not defined $_[0]);
    return if not @_;
    return @_;

}

### autodie clobbering tests ###

eval {
    list_mirror();
};

is($@, "", "No autodie, no fatality");

eval {
    use autodie qw(list_mirror);
    list_mirror();
};

ok($@, "Autodie fatality for empty return in void context");

eval {
    list_mirror();
};

is($@, "", "No autodie, no fatality (after autodie used)");

eval {
    use autodie qw(list_mirror);
    list_mirror(undef);
};

ok($@, "Autodie fatality for undef return in void context");

eval {
    use autodie qw(list_mirror);
    my @list = list_mirror();
};

ok($@,"Autodie fatality for empty list return");

eval {
    use autodie qw(list_mirror);
    my @list = list_mirror(undef);
};

ok($@,"Autodie fatality for undef list return");

eval {
    use autodie qw(list_mirror);
    my @list = list_mirror("tada");
};

ok(! $@,"No Autodie fatality for defined list return");

eval {
    use autodie qw(list_mirror);
    my $single = list_mirror("tada");
};

ok(! $@,"No Autodie fatality for defined scalar return");

eval {
    use autodie qw(list_mirror);
    my $single = list_mirror(undef);
};

ok($@,"Autodie fatality for undefined scalar return");