Commit | Line | Data |
0b09a93a |
1 | #!/usr/bin/perl -w |
2 | use strict; |
3 | use Test::More; |
4 | |
5 | BEGIN { plan skip_all => "Perl 5.10 only tests" if $] < 5.010; } |
6 | |
7 | # These are tests that depend upon 5.10 (eg, smart-match). |
8 | # Basic tests should go in basic_exceptions.t |
9 | |
10 | use 5.010; |
11 | use constant NO_SUCH_FILE => 'this_file_had_better_not_exist_xyzzy'; |
12 | |
13 | plan 'no_plan'; |
14 | |
15 | eval { |
16 | use autodie ':io'; |
17 | open(my $fh, '<', NO_SUCH_FILE); |
18 | }; |
19 | |
20 | ok($@, "Exception thrown" ); |
035fa39e |
21 | ok($@ ~~ 'open', "Exception from open" ); |
22 | ok($@ ~~ ':file', "Exception from open / class :file" ); |
23 | ok($@ ~~ ':io', "Exception from open / class :io" ); |
24 | ok($@ ~~ ':all', "Exception from open / class :all" ); |
0b09a93a |
25 | |
26 | eval { |
27 | no warnings 'once'; # To prevent the following close from complaining. |
28 | close(THIS_FILEHANDLE_AINT_OPEN); |
29 | }; |
30 | |
31 | ok(! $@, "Close without autodie should fail silent"); |
32 | |
33 | eval { |
34 | use autodie ':io'; |
35 | close(THIS_FILEHANDLE_AINT_OPEN); |
36 | }; |
37 | |
38 | like($@, qr{Can't close filehandle 'THIS_FILEHANDLE_AINT_OPEN'},"Nice msg from close"); |
39 | |
40 | ok($@, "Exception thrown" ); |
035fa39e |
41 | ok($@ ~~ 'close', "Exception from close" ); |
42 | ok($@ ~~ ':file', "Exception from close / class :file" ); |
43 | ok($@ ~~ ':io', "Exception from close / class :io" ); |
44 | ok($@ ~~ ':all', "Exception from close / class :all" ); |
0b09a93a |
45 | |