|
Packit |
6427f8 |
#!/usr/bin/perl
|
|
Packit |
6427f8 |
use strict;
|
|
Packit |
6427f8 |
|
|
Packit |
6427f8 |
use Scalar::Util qw(blessed);
|
|
Packit |
6427f8 |
|
|
Packit |
6427f8 |
use constant NO_SUCH_FILE => "this_file_or_dir_had_better_not_exist_XYZZY";
|
|
Packit |
6427f8 |
|
|
Packit |
6427f8 |
use Test::More tests => 7;
|
|
Packit |
6427f8 |
|
|
Packit |
6427f8 |
use Fatal();
|
|
Packit |
6427f8 |
|
|
Packit |
6427f8 |
# Silence the warnings from using Fatal qw(:lexical)
|
|
Packit |
6427f8 |
|
|
Packit |
6427f8 |
# Lexical tests using the internal interface.
|
|
Packit |
6427f8 |
|
|
Packit |
6427f8 |
my @warnings;
|
|
Packit |
6427f8 |
eval {
|
|
Packit |
6427f8 |
# Filter out deprecation warning (no warnings qw(deprecated) does
|
|
Packit |
6427f8 |
# not seem to work for some reason)
|
|
Packit |
6427f8 |
local $SIG{'__WARN__'} = sub {
|
|
Packit |
6427f8 |
push(@warnings, @_) unless $_[0] =~ m/Fatal qw\(:lexical/;
|
|
Packit |
6427f8 |
};
|
|
Packit |
6427f8 |
Fatal->import(qw(:lexical :void))
|
|
Packit |
6427f8 |
};
|
|
Packit |
6427f8 |
like($@, qr{:void cannot be used with lexical}, ":void can't be used with :lexical");
|
|
Packit |
6427f8 |
warn($_) while shift @warnings;
|
|
Packit |
6427f8 |
|
|
Packit |
6427f8 |
eval { Fatal->import(qw(open close :lexical)) };
|
|
Packit |
6427f8 |
like($@, qr{:lexical must be used as first}, ":lexical must come first");
|
|
Packit |
6427f8 |
|
|
Packit |
6427f8 |
{
|
|
Packit |
6427f8 |
BEGIN {
|
|
Packit |
6427f8 |
# Filter out deprecation warning (no warnings qw(deprecated) does
|
|
Packit |
6427f8 |
# not seem to work for some reason)
|
|
Packit |
6427f8 |
local $SIG{'__WARN__'} = sub {
|
|
Packit |
6427f8 |
push(@warnings, @_) unless $_[0] =~ m/Fatal qw\(:lexical/;
|
|
Packit |
6427f8 |
};
|
|
Packit |
6427f8 |
import Fatal qw(:lexical chdir);
|
|
Packit |
6427f8 |
};
|
|
Packit |
6427f8 |
warn($_) while shift @warnings;
|
|
Packit |
6427f8 |
eval { chdir(NO_SUCH_FILE); };
|
|
Packit |
6427f8 |
my $err = $@;
|
|
Packit |
6427f8 |
like ($err, qr/^Can't chdir/, "Lexical fatal chdir");
|
|
Packit |
6427f8 |
{
|
|
Packit |
6427f8 |
no Fatal qw(:lexical chdir);
|
|
Packit |
6427f8 |
eval { chdir(NO_SUCH_FILE); };
|
|
Packit |
6427f8 |
is ($@, "", "No lexical fatal chdir");
|
|
Packit |
6427f8 |
}
|
|
Packit |
6427f8 |
|
|
Packit |
6427f8 |
eval { chdir(NO_SUCH_FILE); };
|
|
Packit |
6427f8 |
$err = $@;
|
|
Packit |
6427f8 |
like ($err, qr/^Can't chdir/, "Lexical fatal chdir returns");
|
|
Packit |
6427f8 |
}
|
|
Packit |
6427f8 |
|
|
Packit |
6427f8 |
eval { chdir(NO_SUCH_FILE); };
|
|
Packit |
6427f8 |
is($@, "", "Lexical chdir becomes non-fatal out of scope.");
|
|
Packit |
6427f8 |
|
|
Packit |
6427f8 |
eval { Fatal->import('2+2'); };
|
|
Packit |
6427f8 |
like($@,qr{Bad subroutine name},"Can't use fatal with invalid sub names");
|