Debian Codegraph @

cpan/autodie/t/eval_error.t

raw
1 #!/usr/bin/perl -w
2 use strict;
3 use warnings;
4 use Test::More 'no_plan';
5 use autodie;
6
7 use constant NO_SUCH_FILE => 'this_file_had_better_not_exist';
8 use constant MAGIC_STRING => 'xyzzy';
9
10 # Opening an eval clears $@, so it's important that we set it
11 # inside the eval block to see if it's successfully captured.
12
13 eval {
14 $@ = MAGIC_STRING;
15 is($@, MAGIC_STRING, 'Sanity check on start conditions');
16 open(my $fh, '<', NO_SUCH_FILE);
17 };
18
19 isa_ok($@, 'autodie::exception');
20 is($@->eval_error, MAGIC_STRING, 'Previous $@ should be captured');