tests for nesting inside catch block
Yuval Kogman [Thu, 3 Sep 2009 02:09:10 +0000 (10:09 +0800)]
t/basic.t

index 400b1fb..ebc4106 100644 (file)
--- a/t/basic.t
+++ b/t/basic.t
@@ -3,7 +3,7 @@
 use strict;
 #use warnings;
 
-use Test::More tests => 15;
+use Test::More tests => 19;
 
 BEGIN { use_ok 'Try::Tiny' };
 
@@ -74,6 +74,34 @@ is( scalar(try { "foo", "bar", "gorch" }), "gorch", "scalar context" );
 is_deeply( [ try {qw(foo bar gorch)} ], [qw(foo bar gorch)], "list context" );
 
 
+lives_ok {
+       try {
+               die "foo";
+       } catch {
+               my $err = shift;
+
+               try {
+                       like $err, qr/foo/;
+               } catch {
+                       fail("shouldn't happen");
+               };
+
+               pass "got here";
+       }
+} "try in try catch block";
+
+throws_ok {
+       try {
+               die "foo";
+       } catch {
+               my $err = shift;
+
+               try { } catch { };
+
+               die "rethrowing $err";
+       }
+} qr/rethrowing foo/, "rethrow with try in catch block";
+
 
 sub Evil::DESTROY {
        eval { "oh noes" };