Explicitly check that our $_; is special, and forced to main::
[p5sagit/p5-mst-13.2.git] / t / op / do.t
old mode 100755 (executable)
new mode 100644 (file)
index 43ce3e8..e47441a
--- a/t/op/do.t
+++ b/t/op/do.t
@@ -29,17 +29,23 @@ sub ok {
     return $ok;
 }
 
-print "1..38\n";
+print "1..50\n";
 
 # Test do &sub and proper @_ handling.
 $_[0] = 0;
-$result = do foo1(1);
+{
+    no warnings 'deprecated';
+    $result = do foo1(1);
+}
 
 ok( $result eq 'value',  ":$result: eq :value:" );
 ok( $_[0] == 0 );
 
 $_[0] = 0;
-$result = do foo2(0,1,0);
+{
+    no warnings 'deprecated';
+    $result = do foo2(0,1,0);
+}
 ok( $result eq 'value', ":$result: eq :value:" );
 ok( $_[0] == 0 );
 
@@ -50,10 +56,16 @@ sub blather {
     ok 1 foreach @_;
 }
 
-do blather("ayep","sho nuff");
+{
+    no warnings 'deprecated';
+    do blather("ayep","sho nuff");
+}
 @x = ("jeepers", "okydoke");
 @y = ("uhhuh", "yeppers");
-do blather(@x,"noofie",@y);
+{
+    no warnings 'deprecated';
+    do blather(@x,"noofie",@y);
+}
 
 unshift @INC, '.';
 
@@ -140,6 +152,45 @@ ok(defined $x && $x == 4, 'return do { do { ; } } receives caller scalar context
 @x = sub { do { return do { 1; do { 2; @a } } }; 5 }->();
 ok("@x" eq "7 8 9 10", 'return do { do { ; } } receives caller list context');
 
+# Do blocks created by constant folding
+# [perl #68108]
+$x = sub { if (1) { 20 } }->();
+ok($x == 20, 'if (1) { $x } receives caller scalar context');
+
+@a = (21 .. 23);
+$x = sub { if (1) { @a } }->();
+ok($x == 3, 'if (1) { @a } receives caller scalar context');
+@x = sub { if (1) { @a } }->();
+ok("@x" eq "21 22 23", 'if (1) { @a } receives caller list context');
+
+$x = sub { if (1) { 0; 20 } }->();
+ok($x == 20, 'if (1) { ...; $x } receives caller scalar context');
+
+@a = (24 .. 27);
+$x = sub { if (1) { 0; @a } }->();
+ok($x == 4, 'if (1) { ...; @a } receives caller scalar context');
+@x = sub { if (1) { 0; @a } }->();
+ok("@x" eq "24 25 26 27", 'if (1) { ...; @a } receives caller list context');
+
+$x = sub { if (1) { 0; 20 } else{} }->();
+ok($x == 20, 'if (1) { ...; $x } else{} receives caller scalar context');
+
+@a = (24 .. 27);
+$x = sub { if (1) { 0; @a } else{} }->();
+ok($x == 4, 'if (1) { ...; @a } else{} receives caller scalar context');
+@x = sub { if (1) { 0; @a } else{} }->();
+ok("@x" eq "24 25 26 27", 'if (1) { ...; @a } else{} receives caller list context');
+
+$x = sub { if (0){} else { 0; 20 } }->();
+ok($x == 20, 'if (0){} else { ...; $x } receives caller scalar context');
+
+@a = (24 .. 27);
+$x = sub { if (0){} else { 0; @a } }->();
+ok($x == 4, 'if (0){} else { ...; @a } receives caller scalar context');
+@x = sub { if (0){} else { 0; @a } }->();
+ok("@x" eq "24 25 26 27", 'if (0){} else { ...; @a } receives caller list context');
+
+
 END {
     1 while unlink("$$.16", "$$.17", "$$.18");
 }