Debian Codegraph @

cpan/autodie/t/Fatal.t

raw
1 #!/usr/bin/perl -w
2 use strict;
3
4 use constant NO_SUCH_FILE => "this_file_or_dir_had_better_not_exist_XYZZY";
5
6 use Test::More tests => 17;
7
8 use Fatal qw(:io :void opendir);
9
10 eval { open FOO, "<".NO_SUCH_FILE }; # Two arg open
11 like($@, qr/^Can't open/, q{Package Fatal::open});
12 is(ref $@, "", "Regular fatal throws a string");
13
14 my $foo = 'FOO';
15 for ('$foo', "'$foo'", "*$foo", "\\*$foo") {
16 eval qq{ open $_, '<$0' };
17
18 is($@,"", "Open using filehandle named - $_");
19
20 like(scalar(<$foo>), qr{^#!.*/perl}, "File contents using - $_");
21 eval qq{ close FOO };
22
23 is($@,"", "Close filehandle using - $_");
24 }
25
26 eval { opendir FOO, NO_SUCH_FILE };
27 like($@, qr{^Can't open}, "Package :void Fatal::opendir");
28
29 eval { my $a = opendir FOO, NO_SUCH_FILE };
30 is($@, "", "Package :void Fatal::opendir in scalar context");
31
32 eval { Fatal->import(qw(print)) };
33 like(
34 $@, qr{Cannot make the non-overridable builtin print fatal},
35 "Can't override print"
36 );