Commit | Line | Data |
db4e6d09 |
1 | #!/usr/bin/perl -w |
2 | use strict; |
3 | use warnings; |
4 | use Test::More 'no_plan'; |
5 | use File::Copy; |
6 | use constant NO_SUCH_FILE => 'this_file_had_better_not_exist'; |
7 | use constant EXCEPTION => 'autodie::exception'; |
8 | |
9 | # http://perlmonks.org/?node_id=744246 describes a situation where |
10 | # using autodie on user-defined functions can fail, depending upon |
11 | # their context. These tests attempt to detect this bug. |
12 | |
13 | eval { |
14 | use autodie qw(copy); |
15 | copy(NO_SUCH_FILE, 'xyzzy'); |
16 | }; |
17 | |
18 | isa_ok($@,EXCEPTION,"Copying a non-existent file should throw an error"); |
19 | |
20 | eval { |
21 | use autodie qw(copy); |
22 | my $x = copy(NO_SUCH_FILE, 'xyzzy'); |
23 | }; |
24 | |
25 | isa_ok($@,EXCEPTION,"This shouldn't change with scalar context"); |
26 | |
27 | eval { |
28 | use autodie qw(copy); |
29 | my @x = copy(NO_SUCH_FILE, 'xyzzy'); |
30 | }; |
31 | |
9b657a62 |
32 | isa_ok($@,EXCEPTION,"This shouldn't change with array context"); |
db4e6d09 |
33 | |
34 | # For good measure, test with built-ins. |
35 | |
36 | eval { |
37 | use autodie qw(open); |
38 | open(my $fh, '<', 'xyzzy'); |
39 | }; |
40 | |
41 | isa_ok($@,EXCEPTION,"Opening a non-existent file should throw an error"); |
42 | |
43 | eval { |
44 | use autodie qw(open); |
45 | my $x = open(my $fh, '<', 'xyzzy'); |
46 | }; |
47 | |
48 | isa_ok($@,EXCEPTION,"This shouldn't change with scalar context"); |
49 | |
50 | eval { |
51 | use autodie qw(open); |
52 | my @x = open(my $fh, '<', 'xyzzy'); |
53 | }; |
54 | |
55 | isa_ok($@,EXCEPTION,"This shouldn't change with array context"); |