summaryrefslogtreecommitdiff
path: root/cpan/autodie/t/context.t
blob: 39b86497c609b42cda28cce4232126af2e525828 (plain)
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
#!/usr/bin/perl -w
use strict;

use Test::More;

plan 'no_plan';

sub list_return {
    return if @_;
    return qw(foo bar baz);
}

sub list_return2 {
    return if @_;
    return qw(foo bar baz);
}

# 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.

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

}

use Fatal qw(list_return);
use Fatal qw(:void list_return2);

TODO: {

    # Clobbering context was documented as a bug in the original
    # Fatal, so we'll still consider it a bug here.

    local $TODO = "Fatal clobbers context, just like it always has.";

    my @list = list_return();

    is_deeply(\@list,[qw(foo bar baz)],'fatal sub works in list context');
}

eval {
    my @line = list_return(1);  # Should die
};

ok($@,"List return fatalised");

### Tests where we've fatalised our function with :void ###

my @list2 = list_return2();

is_deeply(\@list2,[qw(foo bar baz)],'fatal sub works in list context');

eval {
    my @line = list_return2(1);  # Shouldn't die
};

ok(! $@,"void List return fatalised survives when non-void");

eval {
    list_return2(1);
};

ok($@,"void List return fatalised");