1#!/usr/bin/perl 2use strict; 3 4use Scalar::Util qw(blessed); 5 6use constant NO_SUCH_FILE => "this_file_or_dir_had_better_not_exist_XYZZY"; 7 8use Test::More tests => 7; 9 10use Fatal(); 11 12# Silence the warnings from using Fatal qw(:lexical) 13 14# Lexical tests using the internal interface. 15 16my @warnings; 17eval { 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}; 25like($@, qr{:void cannot be used with lexical}, ":void can't be used with :lexical"); 26warn($_) while shift @warnings; 27 28eval { Fatal->import(qw(open close :lexical)) }; 29like($@, 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 55eval { chdir(NO_SUCH_FILE); }; 56is($@, "", "Lexical chdir becomes non-fatal out of scope."); 57 58eval { Fatal->import('2+2'); }; 59like($@,qr{Bad subroutine name},"Can't use fatal with invalid sub names"); 60