Commit | Line | Data |
6b38a9b9 |
1 | #!perl -w |
2 | |
3 | BEGIN { |
4 | if( $ENV{PERL_CORE} ) { |
5 | chdir 't'; |
6 | @INC = ('../lib', 'lib'); |
7 | } |
8 | else { |
9 | unshift @INC, 't/lib'; |
10 | } |
11 | } |
12 | |
13 | use strict; |
14 | |
15 | use Test::More 'no_plan'; |
16 | |
17 | require Test::Builder; |
18 | my $tb = Test::Builder->new; |
19 | |
6b38a9b9 |
20 | |
82d700dc |
21 | # Test that _try() has no effect on $@ and $! and is not effected by |
22 | # __DIE__ |
23 | { |
24 | local $SIG{__DIE__} = sub { fail("DIE handler called: @_") }; |
25 | local $@ = 42; |
26 | local $! = 23; |
6b38a9b9 |
27 | |
82d700dc |
28 | is $tb->_try(sub { 2 }), 2; |
29 | is $tb->_try(sub { return '' }), ''; |
6b38a9b9 |
30 | |
82d700dc |
31 | is $tb->_try(sub { die; }), undef; |
6b38a9b9 |
32 | |
82d700dc |
33 | is_deeply [$tb->_try(sub { die "Foo\n" })], [undef, "Foo\n"]; |
6b38a9b9 |
34 | |
82d700dc |
35 | is $@, 42; |
36 | cmp_ok $!, '==', 23; |
37 | } |
38 | |
39 | ok !eval { |
40 | $tb->_try(sub { die "Died\n" }, die_on_fail => 1); |
41 | }; |
42 | is $@, "Died\n"; |