| 1 |
#!/usr/bin/perl -w |
| 2 |
use strict; |
| 3 |
|
| 4 |
use FindBin; |
| 5 |
use Test::More 'no_plan'; |
| 6 |
|
| 7 |
use lib "$FindBin::Bin/lib"; |
| 8 |
|
| 9 |
use constant NO_SUCH_FILE => "this_file_had_better_not_exist_xyzzy"; |
| 10 |
|
| 11 |
### Tests with non-existent exception class. |
| 12 |
|
| 13 |
my $open_success = eval { |
| 14 |
use autodie::test::missing qw(open); # Uses non-existent exceptions |
| 15 |
open(my $fh, '<', NO_SUCH_FILE); |
| 16 |
1; |
| 17 |
}; |
| 18 |
|
| 19 |
is($open_success,undef,"Open should fail"); |
| 20 |
|
| 21 |
isnt($@,"",'$@ should not be empty'); |
| 22 |
|
| 23 |
is(ref($@),"",'$@ should not be a reference or object'); |
| 24 |
|
| 25 |
like($@, qr/Failed to load/, '$@ should contain bad exception class msg'); |
| 26 |
|
| 27 |
#### Tests with malformed exception class. |
| 28 |
|
| 29 |
my $open_success2 = eval { |
| 30 |
use autodie::test::badname qw(open); |
| 31 |
open(my $fh, '<', NO_SUCH_FILE); |
| 32 |
1; |
| 33 |
}; |
| 34 |
|
| 35 |
is($open_success2,undef,"Open should fail"); |
| 36 |
|
| 37 |
isnt($@,"",'$@ should not be empty'); |
| 38 |
|
| 39 |
is(ref($@),"",'$@ should not be a reference or object'); |
| 40 |
|
| 41 |
like($@, qr/Bad exception class/, '$@ should contain bad exception class msg'); |
| 42 |
|
| 43 |
### Tests with well-formed exception class (in Klingon) |
| 44 |
|
| 45 |
my $open_success3 = eval { |
| 46 |
use pujHa::ghach qw(open); |
| 47 |
open(my $fh, '<', NO_SUCH_FILE); |
| 48 |
1; |
| 49 |
}; |
| 50 |
|
| 51 |
is($open_success3,undef,"Open should fail"); |
| 52 |
|
| 53 |
isnt("$@","",'$@ should not be empty'); |
| 54 |
|
| 55 |
isa_ok($@, "pujHa::ghach::Dotlh", '$@ should be a Klingon exception'); |
| 56 |
|
| 57 |
like($@, qr/lujqu'/, '$@ should contain Klingon text'); |