]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blobdiff - t/58-yield-misc.t
Skip 'yield to subst context' tests on perl 5.8 and below
[perl/modules/Scope-Upper.git] / t / 58-yield-misc.t
index 2eb222ff8e6c07a11715ff57bba2f9b2de2f2a63..3243272da8fcd30f8383803de941d568717ca0a4 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 4 * 3 + 3;
+use Test::More tests => 4 * 3 + 1 + 3;
 
 use lib 't/lib';
 use VPIT::TestHelpers;
@@ -75,6 +75,34 @@ sub guard { VPIT::TestHelpers::Guard->new(sub { ++$destroyed }) }
  is $destroyed, 1, "$desc: destroyed 2";
 }
 
+# Test 'return from do' in special cases
+
+{
+ no warnings 'void';
+ my @res = (1, do {
+  my $cxt = HERE;
+  my $thing = (777, do {
+   my @stuff = (888, do {
+    yield 2, 3 => $cxt;
+    map { my $x; $_ x 3 } qw<x y z>
+   }, 999);
+   if (@stuff) {
+    my $y;
+    ++$y;
+    'YYY';
+   } else {
+    die 'not reached';
+   }
+  });
+  if (1) {
+   my $z;
+   'ZZZ';
+  }
+  'VVV'
+ }, 4);
+ is "@res", '1 2 3 4', 'yield() found the op to return to';
+}
+
 # Test leave
 
 {
@@ -93,7 +121,9 @@ sub guard { VPIT::TestHelpers::Guard->new(sub { ++$destroyed }) }
  is "@res", '1 2 3 4', 'leave with arguments';
 }
 
-{
+SKIP: {
+ skip '"eval { $str =~ s/./die q[foo]/e }" breaks havoc on perl 5.8 and below'
+                                                           => 1 if "$]" < 5.010;
  my $s = 'a';
  local $@;
  eval {
@@ -102,6 +132,6 @@ sub guard { VPIT::TestHelpers::Guard->new(sub { ++$destroyed }) }
  my $err  = $@;
  my $line = __LINE__-3;
  like $err,
-      qr/^leave\(\) cannot target a substitution context at \Q$0\E line $line/,
+      qr/^leave\(\) can't target a substitution context at \Q$0\E line $line/,
       'leave() cannot exit subst';
 }