summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/perl/cpan/autodie/t/user-context.t
blob: 65b6a8876a621c209aea15ad54fa0c1441894fda (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
#!/usr/bin/perl -w
use strict;
use warnings;
use Test::More 'no_plan';
use File::Copy;
use constant NO_SUCH_FILE => 'this_file_had_better_not_exist';
use constant EXCEPTION => 'autodie::exception';

# http://perlmonks.org/?node_id=744246 describes a situation where
# using autodie on user-defined functions can fail, depending upon
# their context.  These tests attempt to detect this bug.

eval {
    use autodie qw(copy);
    copy(NO_SUCH_FILE, 'xyzzy');
};

isa_ok($@,EXCEPTION,"Copying a non-existent file should throw an error");

eval {
    use autodie qw(copy);
    my $x = copy(NO_SUCH_FILE, 'xyzzy');
};

isa_ok($@,EXCEPTION,"This shouldn't change with scalar context");

eval {
    use autodie qw(copy);
    my @x = copy(NO_SUCH_FILE, 'xyzzy');
};

isa_ok($@,EXCEPTION,"This shouldn't change with array context");

# For good measure, test with built-ins.

eval {
    use autodie qw(open);
    open(my $fh, '<', 'xyzzy');
};

isa_ok($@,EXCEPTION,"Opening a non-existent file should throw an error");

eval {
    use autodie qw(open);
    my $x = open(my $fh, '<', 'xyzzy');
};

isa_ok($@,EXCEPTION,"This shouldn't change with scalar context");

eval {
    use autodie qw(open);
    my @x = open(my $fh, '<', 'xyzzy');
};

isa_ok($@,EXCEPTION,"This shouldn't change with array context");