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 | |
32 | TODO: { |
33 | local $TODO = "Fixed in 'hints' branch"; |
34 | |
35 | isa_ok($@,EXCEPTION,"This shouldn't change with array context"); |
36 | } |
37 | |
38 | # For good measure, test with built-ins. |
39 | |
40 | eval { |
41 | use autodie qw(open); |
42 | open(my $fh, '<', 'xyzzy'); |
43 | }; |
44 | |
45 | isa_ok($@,EXCEPTION,"Opening a non-existent file should throw an error"); |
46 | |
47 | eval { |
48 | use autodie qw(open); |
49 | my $x = open(my $fh, '<', 'xyzzy'); |
50 | }; |
51 | |
52 | isa_ok($@,EXCEPTION,"This shouldn't change with scalar context"); |
53 | |
54 | eval { |
55 | use autodie qw(open); |
56 | my @x = open(my $fh, '<', 'xyzzy'); |
57 | }; |
58 | |
59 | isa_ok($@,EXCEPTION,"This shouldn't change with array context"); |