]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blobdiff - t/61-uplevel-args.t
Protect against d_cplusplus perls
[perl/modules/Scope-Upper.git] / t / 61-uplevel-args.t
index 59a9071fe0e5370d6671680781959ce2a664de5c..8a81c21cc17864206acd6e8613982d3e1c7d15b7 100644 (file)
@@ -3,9 +3,9 @@
 use strict;
 use warnings;
 
-use Test::More tests => 9 + 4 * 7 + 3 + ((5 * 4 * 4) * 3 + 1) + 2 + 6;
+use Test::More tests => 9 + 4 * 7 + 3 + ((5 * 4 * 4) * 3 + 1) + 5 + 3 + 2 + 6;
 
-use Scope::Upper qw<uplevel HERE>;
+use Scope::Upper qw<uplevel HERE UP>;
 
 # Basic
 
@@ -149,11 +149,11 @@ sub {
 
 SKIP: {
  if ("$]" < 5.008) {
-  my $cb = sub { fail "should not be executed" };
+  my $cb = sub { fail 'should not be executed' };
   local $@;
   eval { sub { uplevel { goto $cb } HERE }->() };
-  like $@, qr/^Can't goto to an uplevel'd stack frame on perl 5\.6/,
-           "goto croaks";
+  like $@, qr/^uplevel\(\) can't execute code that calls goto before perl 5\.8/,
+           'goto croaks';
   skip "goto to an uplevel'd stack frame does not work on perl 5\.6"
                                                    => ((5 * 4 * 4) * 3 + 1) - 1;
  }
@@ -233,6 +233,62 @@ SKIP: {
  }->('dummy');
 }
 
+# goto XS
+
+SKIP: {
+ skip "goto to an uplevel'd stack frame does not work on perl 5\.6" => 5
+                                                                if "$]" < 5.008;
+
+ my $desc = 'uplevel() calling goto &uplevel';
+ local $@;
+ eval {
+  sub {
+   my $outer_cxt = HERE;
+   sub {
+    my $inner_cxt = HERE;
+    sub {
+     uplevel {
+      is HERE, $inner_cxt, "$desc: context inside first uplevel";
+      is "@_", '1 2 3',    "$desc: arguments inisde first uplevel";
+      unshift @_, 0;
+      push    @_, 4;
+      unshift @_, sub {
+       is HERE, $outer_cxt,  "$desc: context inside second uplevel";
+       is "@_", '0 1 2 3 4', "$desc: arguments inisde second uplevel";
+      };
+      push @_, UP;
+      goto \&uplevel;
+     } 1 .. 3 => UP;
+    }->();
+   }->();
+  }->();
+ };
+ is $@, '', "$desc: no error";
+}
+
+# uplevel() to uplevel()
+
+{
+ my $desc = '\&uplevel as the uplevel() callback';
+ local $@;
+ eval {
+  sub {
+   my $cxt = HERE;
+   sub {
+    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.
+     uplevel(\&uplevel => (sub {
+      is "@_", '1 2 3', "$desc: arguments inisde";
+      is HERE, $cxt,    "$desc: context inside";
+     } => 1 .. 3 => UP) => UP);
+    }->(10 .. 19);
+   }->(sub { die 'wut' } => HERE);
+  }->('dummy');
+ };
+ is $@, '', "$desc: no error";
+}
+
 # Magic
 
 {