xref: /openbsd-src/gnu/usr.bin/perl/cpan/Test-Simple/t/Legacy/Builder/try.t (revision 5759b3d249badf144a6240f7eec4dcf9df003e6b)
1#!perl -w
2
3BEGIN {
4    if( $ENV{PERL_CORE} ) {
5        chdir 't';
6        @INC = ('../lib', 'lib');
7    }
8    else {
9        unshift @INC, 't/lib';
10    }
11}
12
13use strict;
14
15use Test::More 'no_plan';
16
17require Test::Builder;
18my $tb = Test::Builder->new;
19
20
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;
27
28    is $tb->_try(sub { 2 }), 2;
29    is $tb->_try(sub { return '' }), '';
30
31    is $tb->_try(sub { die; }), undef;
32
33    is_deeply [$tb->_try(sub { die "Foo\n" })], [undef, "Foo\n"];
34
35    is $@, 42;
36    cmp_ok $!, '==', 23;
37}
38
39ok !eval {
40    $tb->_try(sub { die "Died\n" }, die_on_fail => 1);
41};
42is $@, "Died\n";
43