]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blobdiff - t/13-reap-ctl.t
Silence experimental warnings on perl 5.17.11+ for given/when in tests
[perl/modules/Scope-Upper.git] / t / 13-reap-ctl.t
index 7ec492a9906c8ffac3d06ad2943533be88c48d0e..e4e47b5e0f9db9b46954a11d4911a83de379d441 100644 (file)
@@ -3,9 +3,9 @@
 use strict;
 use warnings;
 
-use Test::More tests => 38 + 4 * 7;
+use Test::More tests => 41 + 30 + 4 * 7;
 
-use Scope::Upper qw/reap UP HERE/;
+use Scope::Upper qw<reap UP HERE>;
 
 our ($x, $y);
 
@@ -122,6 +122,176 @@ $y = undef;
  is $y, 1, 'die - reap inside eval [ok - y]';
 }
 
+{
+ my $z      = 0;
+ my $reaped = 0;
+ eval {
+  reap { $reaped = 1 };
+  is $reaped, 0, 'died of natural death - not reaped yet';
+  my $res = 1 / $z;
+ };
+ my $err = $@;
+ is   $reaped, 1,                    'died of natural death - reaped';
+ like $err,    qr/division by zero/, 'died of natural death - divided by zero';
+}
+
+SKIP:
+{
+ skip 'Perl 5.10 required to test given/when' => 30 if "$]" < 5.010;
+
+ eval <<' GIVEN_TEST_1';
+  BEGIN {
+   if ("$]" >= 5.017_011) {
+    require warnings;
+    warnings->unimport('experimental::smartmatch');
+   }
+  }
+  use feature 'switch';
+  local $y;
+  {
+   local $x = 1;
+   given (1) {
+    local $x = 2;
+    when (1) {
+     local $x = 3;
+     reap \&check => UP;
+     is $x, 3,     'given/when - reap at given [not yet - x]';
+     is $y, undef, 'given/when - reap at given [not yet - y]';
+    }
+    fail 'not reached';
+   }
+   is $x, 1, 'given/when - reap at given [ok - x]';
+   is $y, 1, 'given/when - reap at given [ok - y]';
+  }
+ GIVEN_TEST_1
+ fail $@ if $@;
+
+ eval <<' GIVEN_TEST_2';
+  BEGIN {
+   if ("$]" >= 5.017_011) {
+    require warnings;
+    warnings->unimport('experimental::smartmatch');
+   }
+  }
+  use feature 'switch';
+  local $y;
+  {
+   local $x = 1;
+   given (1) {
+    local $x = 2;
+    when (1) {
+     local $x = 3;
+     reap \&check => UP;
+     is $x, 3,     'given/when/continue - reap at given [not yet 1 - x]';
+     is $y, undef, 'given/when/continue - reap at given [not yet 1 - y]';
+     continue;
+    }
+    is $x, 2,     'given/when/continue - reap at given [not yet 2 - x]';
+    is $y, undef, 'given/when/continue - reap at given [not yet 2 - y]';
+   }
+   is $x, 1, 'given/when/continue - reap at given [ok - x]';
+   is $y, 1, 'given/when/continue - reap at given [ok - y]';
+  }
+ GIVEN_TEST_2
+ fail $@ if $@;
+
+ eval <<' GIVEN_TEST_3';
+  BEGIN {
+   if ("$]" >= 5.017_011) {
+    require warnings;
+    warnings->unimport('experimental::smartmatch');
+   }
+  }
+  use feature 'switch';
+  local $y;
+  {
+   local $x = 1;
+   given (1) {
+    local $x = 2;
+    default {
+     local $x = 3;
+     reap \&check => UP;
+     is $x, 3,     'given/default - reap at given [not yet - x]';
+     is $y, undef, 'given/default - reap at given [not yet - y]';
+    }
+    fail 'not reached';
+   }
+   is $x, 1, 'given/default - reap at given [ok - x]';
+   is $y, 1, 'given/default - reap at given [ok - y]';
+  }
+ GIVEN_TEST_3
+ fail $@ if $@;
+
+ eval <<' GIVEN_TEST_4';
+  BEGIN {
+   if ("$]" >= 5.017_011) {
+    require warnings;
+    warnings->unimport('experimental::smartmatch');
+   }
+  }
+  use feature 'switch';
+  local $y;
+  {
+   local $x = 1;
+   given (1) {
+    local $x = 2;
+    default {
+     local $x = 3;
+     reap \&check => UP;
+     is $x, 3,     'given/default/continue - reap at given [not yet 1 - x]';
+     is $y, undef, 'given/default/continue - reap at given [not yet 1 - y]';
+     continue;
+    }
+    is $x, 2,     'given/default/continue - reap at given [not yet 2 - x]';
+    is $y, undef, 'given/default/continue - reap at given [not yet 2 - y]';
+   }
+   is $x, 1, 'given/default/continue - reap at given [ok - x]';
+   is $y, 1, 'given/default/continue - reap at given [ok - y]';
+  }
+ GIVEN_TEST_4
+ fail $@ if $@;
+
+ eval <<' GIVEN_TEST_5';
+  BEGIN {
+   if ("$]" >= 5.017_011) {
+    require warnings;
+    warnings->unimport('experimental::smartmatch');
+   }
+  }
+  use feature 'switch';
+  local $y;
+  {
+   local $x = 1;
+   given (1) {
+    local $x = 2;
+    default {
+     local $x = 3;
+     given (2) {
+      local $x = 4;
+      when (2) {
+       local $x = 5;
+       reap \&check => UP UP;
+       is $x, 5,     'given/default/given/when - reap at default [not yet 1 - x]';
+       is $y, undef, 'given/default/given/when - reap at default [not yet 1 - y]';
+       continue;
+      }
+      is $x, 4,     'given/default/given/when - reap at default [not yet 2 - x]';
+      is $y, undef, 'given/default/given/when - reap at default [not yet 2 - y]';
+     }
+     is $x, 3,     'given/default/given/when - reap at default [not yet 3 - x]';
+     is $y, undef, 'given/default/given/when - reap at default [not yet 3 - y]';
+     continue;
+    }
+    is $x, 2, 'given/default/given/when - reap at default [ok 1 - x]';
+    is $y, 1, 'given/default/given/when - reap at default [ok 1 - y]';
+   }
+   is $x, 1, 'given/default/given/when - reap at default [ok 2 - x]';
+   is $y, 1, 'given/default/given/when - reap at default [ok 2 - y]';
+  }
+ GIVEN_TEST_5
+ fail $@ if $@;
+}
+
 $y = undef;
 {
  local $x = 1;