4 use constant NO_SUCH_FILE => 'this_file_had_so_better_not_be_here';
6 use Test::More tests => 19;
12 eval { open(my $fh, '<', NO_SUCH_FILE); };
13 like($@,qr{Can't open},"autodie qw(open) in lexical scope");
17 eval { open(my $fh, '<', NO_SUCH_FILE); };
18 is($@,"","no autodie qw(open) in lexical scope");
21 eval { open(my $fh, '<', NO_SUCH_FILE); };
22 like($@,qr{Can't open},"autodie qw(open) in lexical scope 2");
24 no autodie; # Should turn off all autodying subs
25 eval { open(my $fh, '<', NO_SUCH_FILE); };
26 is($@,"","no autodie in lexical scope 2");
28 # Turn our pragma on one last time, so we can verify that
29 # falling out of this block reverts it back to previous
32 eval { open(my $fh, '<', NO_SUCH_FILE); };
33 like($@,qr{Can't open},"autodie qw(open) in lexical scope 3");
37 eval { open(my $fh, '<', NO_SUCH_FILE); };
38 is($@,"","autodie open outside of lexical scope");
41 use autodie; # Should turn on everything
42 open(my $fh, '<', NO_SUCH_FILE);
45 like($@, qr{Can't open}, "vanilla use autodie turns on everything.");
47 eval { open(my $fh, '<', NO_SUCH_FILE); };
48 is($@,"","vanilla autodie cleans up");
53 eval { open(my $fh, '<', NO_SUCH_FILE); };
54 like($@,qr{Can't open},"autodie q(:io) makes autodying open");
58 eval { open(my $fh, '<', NO_SUCH_FILE); };
59 is($@,"", "no autodie qw(:io) disabled autodying open");
63 package Testing_autodie;
67 use constant NO_SUCH_FILE => ::NO_SUCH_FILE();
71 eval { open(my $fh, '<', NO_SUCH_FILE); };
73 like($@, qr{Can't open}, "Package fatal working");
74 is(ref $@,"","Old Fatal throws strings");
79 ok(1,"use autodie allowed with Fatal");
81 eval { open(my $fh, '<', NO_SUCH_FILE); };
82 like($@, qr{Can't open}, "autodie and Fatal works");
83 isa_ok($@, "autodie::exception"); # autodie throws real exceptions
87 eval { open(my $fh, '<', NO_SUCH_FILE); };
89 like($@, qr{Can't open}, "Package fatal working after autodie");
90 is(ref $@,"","Old Fatal throws strings after autodie");
92 eval " no autodie qw(open); ";
94 ok($@,"no autodie on Fataled sub an error.");
101 like($@, qr{not allowed}, "Using fatal after autodie is an error.");