]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blobdiff - t/13-reap-ctl.t
We don't really need a more lexical $_ in the test given blocks
[perl/modules/Scope-Upper.git] / t / 13-reap-ctl.t
index 5dd5ea91d099bc4aedb3229ac80d896664192577..7ec492a9906c8ffac3d06ad2943533be88c48d0e 100644 (file)
@@ -3,9 +3,9 @@
 use strict;
 use warnings;
 
-use Test::More tests => 38;
+use Test::More tests => 38 + 4 * 7;
 
-use Scope::Upper qw/reap/;
+use Scope::Upper qw/reap UP HERE/;
 
 our ($x, $y);
 
@@ -16,7 +16,7 @@ sub check { ++$y }
  {
   local $x = 2;
   {
-   reap \&check => 1;
+   reap \&check => UP;
   }
   is $x, 2,     'goto 1 [not yet - x]';
   is $y, undef, 'goto 1 [not yet - y]';
@@ -39,7 +39,7 @@ $y = undef;
   {
    local $x = 3;
    {
-    reap \&check => 2;
+    reap \&check => UP UP;
    }
    is $x, 3,     'goto 2 [not yet - x]';
    is $y, undef, 'goto 2 [not yet - y]';
@@ -64,7 +64,7 @@ $y = undef;
    {
     {
      local $x = 3;
-     reap \&check => 3;
+     reap \&check => UP UP UP;
      is $x, 3,     'die - reap outside eval [not yet 1 - x]';
      is $y, undef, 'die - reap outside eval [not yet 1 - y]';
     }
@@ -88,7 +88,7 @@ $y = undef;
   {
    {
     local $x = 3;
-    reap \&check => 2;
+    reap \&check => UP UP;
     is $x, 3,     'die - reap at eval [not yet 1 - x]';
     is $y, undef, 'die - reap at eval [not yet 1 - y]';
    }
@@ -109,7 +109,7 @@ $y = undef;
   {
    {
     local $x = 3;
-    reap \&check => 1;
+    reap \&check => UP;
     is $x, 3,     'die - reap inside eval [not yet 1 - x]';
     is $y, undef, 'die - reap inside eval [not yet 1 - y]';
    }
@@ -129,7 +129,7 @@ $y = undef;
   local $x = 2;
   eval {
    local $x = 3;
-   reap { ++$y; die "reaped\n" } => 0;
+   reap { ++$y; die "reaped\n" } => HERE;
    is $x, 3,     'die in reap at eval [not yet - x]';
    is $y, undef, 'die in reap at eval [not yet - y]';
   }; # should trigger here, but the die isn't catched by this eval
@@ -137,7 +137,7 @@ $y = undef;
  };
  is $@, "reaped\n", 'die in reap at eval [ok - $@]';
  is $x, 1, 'die in reap at eval [ok - x]';
- is $y, 1, 'die in reap at Eval [ok - y]';
+ is $y, 1, 'die in reap at eval [ok - y]';
 }
 
 $y = undef;
@@ -147,7 +147,7 @@ $y = undef;
   local $x = 2;
   {
    local $x = 3;
-   reap { ++$y; die "reaped\n" } => 0;
+   reap { ++$y; die "reaped\n" } => HERE;
    is $x, 3,     'die in reap inside eval [not yet - x]';
    is $y, undef, 'die in reap inside eval [not yet - y]';
   } # should trigger here
@@ -157,3 +157,42 @@ $y = undef;
  is $x, 1, 'die in reap inside eval [ok - x]';
  is $y, 1, 'die in reap inside eval [ok - y]';
 }
+
+sub hijacked {
+ my ($cb, $desc) = @_;
+ local $x = 2;
+ sub {
+  local $x = 3;
+  &reap($cb => UP);
+  is $x, 3,     "$desc [not yet 1 - x]";
+  is $y, undef, "$desc [not yet 1 - y]";
+ }->();
+ is $x, 2,     "$desc [not yet 2 - x]";
+ is $y, undef, "$desc [not yet 2 - y]";
+ 11, 12;
+}
+
+for ([ sub { ++$y; 15, 16, 17, 18 },        'implicit ' ],
+     [ sub { ++$y; return 15, 16, 17, 18 }, ''          ]) {
+ my ($cb, $imp) = @$_;
+ $imp = "RT #44204 - ${imp}return from reap";
+ my $desc;
+ $y = undef;
+ {
+  $desc = "$imp in list context";
+  local $x = 1;
+  my @l = hijacked($cb, $desc);
+  is $x,         1,          "$desc [ok - x]";
+  is $y,         1,          "$desc [ok - y]";
+  is_deeply \@l, [ 11, 12 ], "$desc [ok - l]";
+ }
+ $y = undef;
+ {
+  $desc = "$imp in list context";
+  local $x = 1;
+  my $s = hijacked($cb, $desc);
+  is $x, 1,  "$desc [ok - x]";
+  is $y, 1,  "$desc [ok - y]";
+  is $s, 12, "$desc [ok - s]";
+ }
+}