Debian Codegraph @

cpan/autodie/t/internal.t

raw
1 #!/usr/bin/perl
2 use strict;
3
4 use Scalar::Util qw(blessed);
5
6 use constant NO_SUCH_FILE => "this_file_or_dir_had_better_not_exist_XYZZY";
7
8 use Test::More tests => 7;
9
10 use Fatal();
11
12 # Silence the warnings from using Fatal qw(:lexical)
13
14 # Lexical tests using the internal interface.
15
16 my @warnings;
17 eval {
18 # Filter out deprecation warning (no warnings qw(deprecated) does
19 # not seem to work for some reason)
20 local $SIG{'__WARN__'} = sub {
21 push(@warnings, @_) unless $_[0] =~ m/Fatal qw\(:lexical/;
22 };
23 Fatal->import(qw(:lexical :void))
24 };
25 like($@, qr{:void cannot be used with lexical}, ":void can't be used with :lexical");
26 warn($_) while shift @warnings;
27
28 eval { Fatal->import(qw(open close :lexical)) };
29 like($@, qr{:lexical must be used as first}, ":lexical must come first");
30
31 {
32 BEGIN {
33 # Filter out deprecation warning (no warnings qw(deprecated) does
34 # not seem to work for some reason)
35 local $SIG{'__WARN__'} = sub {
36 push(@warnings, @_) unless $_[0] =~ m/Fatal qw\(:lexical/;
37 };
38 import Fatal qw(:lexical chdir);
39 };
40 warn($_) while shift @warnings;
41 eval { chdir(NO_SUCH_FILE); };
42 my $err = $@;
43 like ($err, qr/^Can't chdir/, "Lexical fatal chdir");
44 {
45 no Fatal qw(:lexical chdir);
46 eval { chdir(NO_SUCH_FILE); };
47 is ($@, "", "No lexical fatal chdir");
48 }
49
50 eval { chdir(NO_SUCH_FILE); };
51 $err = $@;
52 like ($err, qr/^Can't chdir/, "Lexical fatal chdir returns");
53 }
54
55 eval { chdir(NO_SUCH_FILE); };
56 is($@, "", "Lexical chdir becomes non-fatal out of scope.");
57
58 eval { Fatal->import('2+2'); };
59 like($@,qr{Bad subroutine name},"Can't use fatal with invalid sub names");