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