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 );
61 is( try { 42 }, 42, "try block evaluated" );
62 is( $@, "magic", '$@ untouched' );
67 is( try { die "foo" }, undef, "try block died" );
68 is( $@, "magic", '$@ untouched' );
73 like( (try { die "foo" } catch { $_ }), qr/foo/, "catch block evaluated" );
74 is( $@, "magic", '$@ untouched' );
77 is( scalar(try { qw(foo bar gorch) }), "gorch", "scalar context" );
78 is_deeply( [ try {qw(foo bar gorch)} ], [qw(foo bar gorch)], "list context" );
84 local $_ = "other magic";
87 my $object = bless { }, "Evil";
90 pass("catch invoked");
91 local $TODO = "i don't think we can ever make this work sanely, maybe with SIG{__DIE__}";
95 is( $@, "magic", '$@ untouched' );
96 is( $_, "other magic", '$_ untouched' );