]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blobdiff - t/60-uplevel-target.t
fix unwind()
[perl/modules/Scope-Upper.git] / t / 60-uplevel-target.t
index 1dcf3251b71591ec061af186942079d9f5dd6436..87444ba701299b695bd5c26f26096a04ccf5eafb 100644 (file)
@@ -3,7 +3,8 @@
 use strict;
 use warnings;
 
-use Test::More tests => (1 * 3 + 2 * 4 + 3 * 5) * 2 + 7 + 5 + 6 + 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<uplevel HERE UP TOP>;
 
@@ -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
 
 {
@@ -226,7 +260,9 @@ 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';
@@ -237,6 +273,7 @@ sub four {
     ++$lexical;
     is $destroyed, 0, "$desc: not yet 1";
    };
+   $code = bless $code, 'Scope::Upper::TestCodeDestruction';
 
    eval {
     sub {
@@ -251,7 +288,7 @@ sub four {
    is $destroyed, 0,  "$desc: not yet 3";
   };
 
-  is $destroyed, 0,  "$desc: code is destroyed";
+  is $destroyed, 1, "$desc: code is destroyed";
  }
 
  SKIP: {