X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F60-uplevel-target.t;h=87444ba701299b695bd5c26f26096a04ccf5eafb;hb=8aa5517d42b61e877ca7e4198f12ab879fa8218b;hp=6b3a444742fe6a057e2930389e9a3790cc5d26e9;hpb=1da764455f3f82a24aad0881beb01f5e4d3cf858;p=perl%2Fmodules%2FScope-Upper.git diff --git a/t/60-uplevel-target.t b/t/60-uplevel-target.t index 6b3a444..87444ba 100644 --- a/t/60-uplevel-target.t +++ b/t/60-uplevel-target.t @@ -3,7 +3,8 @@ use strict; use warnings; -use Test::More tests => (1 * 3 + 2 * 4 + 3 * 5) * 2 + 7 + 5 + 6 + 5; +use Test::More + tests => (1 * 3 + 2 * 4 + 3 * 5) * 2 + 7 + 7 + (5 + 6 + 5 + 6 + 5); use Scope::Upper qw; @@ -120,6 +121,39 @@ sub four { like $@, qr/^Can't uplevel to an eval frame/, "$desc: dies"; } +# XS + +{ + my $desc = 'uplevel to XS 1'; + local $@; + eval { + sub { + my $cxt = HERE; + pass "$desc: before"; + &uplevel(\&HERE => $cxt); + is HERE, $cxt, "$desc: after"; + }->(); + }; + is $@, '', "$desc: no error"; +} + +{ + my $desc = 'uplevel to XS 1'; + local $@; + eval { + sub { + my $up = HERE; + sub { + is UP, $up, "$desc: before"; + &uplevel(\&HERE => $up); + isnt HERE, $up, "$desc: after 1"; + }->(); + is HERE, $up, "$desc: after 2"; + }->(); + }; + is $@, '', "$desc: no error"; +} + # Target destruction { @@ -225,4 +259,63 @@ sub four { is $destroyed, 1, "$desc: target is detroyed"; } + + SKIP: { + skip 'This fails even with a plain subroutine call on 5.8.x' => 6 + if "$]" < 5.009; + local $@; + local $destroyed = 0; + my $desc = 'code destruction'; + + { + my $lexical; + my $code = sub { + ++$lexical; + is $destroyed, 0, "$desc: not yet 1"; + }; + $code = bless $code, 'Scope::Upper::TestCodeDestruction'; + + eval { + sub { + sub { + &uplevel($code, UP); + is $destroyed, 0, "$desc: not yet 2"; + }->(); + is $destroyed, 0, "$desc: not yet 2"; + }->(); + }; + is $@, '', "$desc: no error"; + is $destroyed, 0, "$desc: not yet 3"; + }; + + is $destroyed, 1, "$desc: code is destroyed"; + } + + SKIP: { + skip 'This fails even with a plain subroutine call on 5.8.x' => 5 + if "$]" < 5.009; + local $@; + local $destroyed = 0; + my $desc = 'code destruction and goto'; + + { + my $lexical = 0; + my $cb = sub { + ++$lexical; + is $destroyed, 0, "$desc: not yet 1"; + }; + $cb = bless $cb, 'Scope::Upper::TestCodeDestruction'; + + eval { + sub { + &uplevel(sub { goto $cb } => HERE); + is $destroyed, 0, "$desc: not yet 2"; + }->(); + }; + is $@, '', "$desc: no error"; + is $destroyed, 0, "$desc: not yet 3"; + } + + is $destroyed, 1, "$desc: code is destroyed"; + } }