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