Re: overriding builtins quirk
[p5sagit/p5-mst-13.2.git] / t / op / grep.t
index 3a7f8ad..6e60813 100755 (executable)
@@ -4,7 +4,7 @@
 # grep() and map() tests
 #
 
-print "1..27\n";
+print "1..33\n";
 
 $test = 1;
 
@@ -97,3 +97,41 @@ sub ok {
              { $_ & "X" } ("ok $test\n");
    $test++;
 }
+
+# Tests for "for" in "map" and "grep"
+# Used to dump core, bug [perl #17771]
+
+{
+    my @x;
+    my $y = '';
+    @x = map { $y .= $_ for 1..2; 1 } 3..4;
+    print "# @x,$y\n";
+    print "@x,$y" eq "1 1,1212" ? "ok $test\n" : "not ok $test\n";
+    $test++;
+    $y = '';
+    @x = map { $y .= $_ for 1..2; $y .= $_ } 3..4;
+    print "# @x,$y\n";
+    print "@x,$y" eq "123 123124,123124" ? "ok $test\n" : "not ok $test\n";
+    $test++;
+    $y = '';
+    @x = map { for (1..2) { $y .= $_ } $y .= $_ } 3..4;
+    print "# @x,$y\n";
+    print "@x,$y" eq "123 123124,123124" ? "ok $test\n" : "not ok $test\n";
+    $test++;
+    $y = '';
+    @x = grep { $y .= $_ for 1..2; 1 } 3..4;
+    print "# @x,$y\n";
+    print "@x,$y" eq "3 4,1212" ? "ok $test\n" : "not ok $test\n";
+    $test++;
+    $y = '';
+    @x = grep { for (1..2) { $y .= $_ } 1 } 3..4;
+    print "# @x,$y\n";
+    print "@x,$y" eq "3 4,1212" ? "ok $test\n" : "not ok $test\n";
+    $test++;
+
+    # Add also a sample test from [perl #18153].  (The same bug).
+    $a = 1; map {if ($a){}} (2);
+    print "ok $test\n"; # no core dump is all we need
+    $test++;
+}
+