X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F62-uplevel-return.t;h=89bc22aed353a8b9dd082aba2bdbce89d1ade1a0;hb=bed9ac0713800543385ae073d3c046fb3390190a;hp=ccf763bd1528a47ccd3e8ed6a90c0b6ffd15c025;hpb=c85df5478ff2d9380ee42b0e5a70461d063745d6;p=perl%2Fmodules%2FScope-Upper.git diff --git a/t/62-uplevel-return.t b/t/62-uplevel-return.t index ccf763b..89bc22a 100644 --- a/t/62-uplevel-return.t +++ b/t/62-uplevel-return.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => (13 + 5 + 4) * 2 + 1 + 3 + 11; +use Test::More tests => (13 + 5 + 4) * 2 + 1 + (3 + 3 + 1) + 2 + 4 + 11; use Scope::Upper qw; @@ -78,6 +78,20 @@ for my $run (1 .. 3) { is $cb->(), 124, "near closure returned by uplevel still works"; } +{ + my $id = 456; + for my $run (1 .. 3) { + my ($cb) = sub { + uplevel { + my $step = 2; + sub { $id += $step }; + }; + }->('dummy'); + is $cb->(), 456 + 2 * $run, "far closure returned by uplevel still works"; + } + is $id, 456 + 2 * 3, 'captured lexical has the right value at the end'; +} + # Mark { @@ -135,6 +149,57 @@ for my $run (1 .. 3) { is_deeply \@ret, [ qw|< ( A B [ { * } ] Z ) >| ], "$desc: outside"; } +# goto + +SKIP: { + skip "goto to an uplevel'd stack frame does not work on perl 5\.6" + => 2 if "$]" < 5.008; + + { + my $desc = 'values returned from goto'; + local $@; + my $cb = sub { 'hello' }; + my @ret = eval { + 'a', sub { + 'b', sub { + 'c', &uplevel(sub { + 'd', (goto $cb), 'w' + } => UP), 'x' + }->(), 'y' + }->(), 'z' + }; + is $@, '', "$desc: did not croak"; + is_deeply \@ret, [ qw ], "$desc: returned values"; + } +} + +# uplevel() to uplevel() + +{ + my $desc = '\&uplevel as the uplevel() callback'; + local $@; + eval { + my @ret = sub { + my $cxt = HERE; + my @ret = sub { + my @ret = sub { + # Note that an XS call does not need a context, so after the first uplevel + # call UP will point to the scope above the first target. + 'a', uplevel(\&uplevel => (sub { + return qw; + } => UP) => UP), 'b'; + }->(); + is "@ret", 'a x y z b', "$desc: returned from uplevel"; + return qw; + }->(); + is "@ret", 'u v w', "$desc: returned from the first target"; + return qw; + }->(); + is "@ret", 'm n', "$desc: returned from the second target"; + }; + is $@, '', "$desc: no error"; +} + # Magic {