6 use Test::More tests => 15;
8 BEGIN { use_ok 'Try::Tiny' };
12 local $Test::Builder::Level = $Test::Builder::Level + 2;
13 return ( scalar(eval { $_[0]->(); 1 }), $@ );
18 my ( $code, $desc ) = @_;
19 local $Test::Builder::Level = $Test::Builder::Level + 1;
21 my ( $ok, $error ) = _eval($code);
25 diag "error: $@" unless $ok;
29 my ( $code, $regex, $desc ) = @_;
30 local $Test::Builder::Level = $Test::Builder::Level + 1;
32 my ( $ok, $error ) = _eval($code);
37 like($error || '', $regex, $desc );
57 is( try { 42 }, 42, "try block evaluated" );
58 is( $@, "magic", '$@ untouched' );
63 is( try { die "foo" }, undef, "try block died" );
64 is( $@, "magic", '$@ untouched' );
69 like( (try { die "foo" } catch { $_ }), qr/foo/, "catch block evaluated" );
70 is( $@, "magic", '$@ untouched' );
73 is( scalar(try { qw(foo bar gorch) }), "gorch", "scalar context" );
74 is_deeply( [ try {qw(foo bar gorch)} ], [qw(foo bar gorch)], "list context" );
82 sub Evil::new { bless { }, $_[0] }
86 local $_ = "other magic";
89 my $object = Evil->new;
92 pass("catch invoked");
93 local $TODO = "i don't think we can ever make this work sanely, maybe with SIG{__DIE__}";
97 is( $@, "magic", '$@ untouched' );
98 is( $_, "other magic", '$_ untouched' );