From: Vincent Pit Date: Sun, 4 Sep 2011 15:40:14 +0000 (+0200) Subject: Test unwinding while unwinding X-Git-Tag: rt71212~5 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=55b2ba8d1101c9edc5c37e8913493e1e45097c83;p=perl%2Fmodules%2FScope-Upper.git Test unwinding while unwinding --- diff --git a/t/55-unwind-multi.t b/t/55-unwind-multi.t index 59c869c..07df3eb 100644 --- a/t/55-unwind-multi.t +++ b/t/55-unwind-multi.t @@ -3,9 +3,9 @@ use strict; use warnings; -use Test::More tests => 13; +use Test::More tests => 13 + 3; -use Scope::Upper qw; +use Scope::Upper qw; my ($l1, $l2); @@ -63,3 +63,42 @@ $l1 = 5; $l2 = 999; is_deeply [ a() ], [ qw, 'in a' ], 'l1=5, l2=?'; + +# Unwinding while unwinding +{ + package Scope::Upper::TestGuard; + + sub new { + my $class = shift; + bless { cb => $_[0] }, $class; + } + + sub DESTROY { + $_[0]->{cb}->() + } +} + +{ + my $desc = 'unwinding while unwinding'; + local $@; + + eval { + my @res = sub { + sub { + my $guard = Scope::Upper::TestGuard->new(sub { + my @res = sub { + sub { + unwind @_ => CALLER(1); + }->(@_); + fail "$desc (second): not reached"; + }->(qw); + is_deeply \@res, [ qw ], "$desc (second): correct returned values"; + }); + unwind @_ => CALLER(1); + }->(@_); + fail "$desc (first): not reached"; + }->(qw); + is_deeply \@res, [ qw ], "$desc (first): correct returned values"; + }; + is $@, '', "$desc: did not croak"; +}