4 use Test::More tests => 17;
6 use constant NO_SUCH_FILE => "this_file_had_better_not_exist";
12 $line = __LINE__; open(my $fh, '<', NO_SUCH_FILE);
15 like($@, qr/Can't open '\w+' for reading: /, "Prety printed open msg");
16 like($@, qr{\Q$0\E}, "Our file mention in error message");
18 like($@, qr{for reading: '.+'}, "Error should be in single-quotes");
19 like($@->errno,qr/./, "Errno should not be empty");
21 like($@, qr{\n$}, "Errors should end with a newline");
22 is($@->file, $0, "Correct file");
23 is($@->function, 'CORE::open', "Correct dying sub");
24 is($@->package, __PACKAGE__, "Correct package");
25 is($@->caller,__PACKAGE__."::__ANON__", "Correct caller");
26 is($@->line, $line, "Correct line");
27 is($@->args->[1], '<', 'Correct mode arg');
28 is($@->args->[2], NO_SUCH_FILE, 'Correct filename arg');
29 ok($@->matches('open'), 'Looks like an error from open');
30 ok($@->matches(':io'), 'Looks like an error from :io');
32 # Testing of caller info with a real subroutine.
38 $line2 = __LINE__; open(my $fh, '<', NO_SUCH_FILE);
44 isa_ok($@, 'autodie::exception');
45 is($@->caller, __PACKAGE__."::xyzzy", "Subroutine caller test");
46 is($@->line, $line2, "Subroutine line test");