Blame t/basic_exceptions.t

Packit 6427f8
#!/usr/bin/perl -w
Packit 6427f8
use strict;
Packit 6427f8
Packit 6427f8
use Test::More tests => 19;
Packit 6427f8
Packit 6427f8
use constant NO_SUCH_FILE => "this_file_had_better_not_exist";
Packit 6427f8
Packit 6427f8
my $line;
Packit 6427f8
Packit 6427f8
eval {
Packit 6427f8
	use autodie ':io';
Packit 6427f8
	$line = __LINE__; open(my $fh, '<', NO_SUCH_FILE);
Packit 6427f8
};
Packit 6427f8
Packit 6427f8
like($@, qr/Can't open '\w+' for reading: /, "Prety printed open msg");
Packit 6427f8
like($@, qr{\Q$0\E}, "Our file mention in error message");
Packit 6427f8
Packit 6427f8
like($@, qr{for reading: '.+'}, "Error should be in single-quotes");
Packit 6427f8
like($@->errno,qr/./, "Errno should not be empty");
Packit 6427f8
Packit 6427f8
like($@, qr{\n$}, "Errors should end with a newline");
Packit 6427f8
is($@->file, $0, "Correct file");
Packit 6427f8
is($@->function, 'CORE::open', "Correct dying sub");
Packit 6427f8
is($@->package, __PACKAGE__, "Correct package");
Packit 6427f8
is($@->caller,__PACKAGE__."::__ANON__", "Correct caller");
Packit 6427f8
is($@->line, $line, "Correct line");
Packit 6427f8
is($@->args->[1], '<', 'Correct mode arg');
Packit 6427f8
is($@->args->[2], NO_SUCH_FILE, 'Correct filename arg');
Packit 6427f8
ok($@->matches('open'), 'Looks like an error from open');
Packit 6427f8
ok($@->matches(':io'),  'Looks like an error from :io');
Packit 6427f8
is($@->context, 'scalar', 'Open called in scalar/void context');
Packit 6427f8
is($@->return,undef,'Open should return undef on failure');
Packit 6427f8
Packit 6427f8
# Testing of caller info with a real subroutine.
Packit 6427f8
Packit 6427f8
my $line2;
Packit 6427f8
Packit 6427f8
sub xyzzy {
Packit 6427f8
    use autodie ':io';
Packit 6427f8
    $line2 = __LINE__; open(my $fh, '<', NO_SUCH_FILE);
Packit 6427f8
    return;
Packit 6427f8
};
Packit 6427f8
Packit 6427f8
eval { xyzzy(); };
Packit 6427f8
Packit 6427f8
isa_ok($@, 'autodie::exception');
Packit 6427f8
is($@->caller, __PACKAGE__."::xyzzy", "Subroutine caller test");
Packit 6427f8
is($@->line, $line2, "Subroutine line test");