]> git.vpit.fr Git - perl/modules/autovivification.git/blobdiff - t/43-peep.t
Also mark the unstack ops in our peephole optimizer
[perl/modules/autovivification.git] / t / 43-peep.t
index 5050821837fb71cb464548316546ee4e139beeb3..88d2afd7082c8d77ddb33e4b7ebb21570b6b1512 100644 (file)
@@ -1,9 +1,14 @@
-#!perl -T
+#!perl
 
 use strict;
 use warnings;
 
-use Test::More tests => 11 + 6 * 3;
+use Test::More;
+
+use lib 't/lib';
+use VPIT::TestHelpers;
+
+plan tests => 11 + 5 * 2 + 5 * 3;
 
 {
  my $desc = 'peephole optimization of conditionals';
@@ -108,26 +113,57 @@ use Test::More tests => 11 + 6 * 3;
 }
 
 {
- my $desc = 'peephole optimization of empty loops (RT #64435)';
- my $x;
-
- local $@;
- my $code = eval <<' TESTCASE';
-  no autovivification;
-  sub {
+ my $base_desc = 'peephole optimization of infinite';
+ my %infinite_tests = (
+  "$base_desc for loops (RT #64435)" => <<'  TESTCASE',
+   no autovivification;
    my $ret = 0;
    for (;;) {
     ++$ret;
-    return $ret;
+    exit $ret;
    }
-   return $ret;
-  }
- TESTCASE
- is $@, '', "$desc compiled fine";
-
- my $ret = $code->();
- is_deeply $x, undef, "$desc did not autovivify";
- is      $ret, 1,     "$desc returned 1";
+   exit $ret;
+  TESTCASE
+  "$base_desc while loops" => <<'  TESTCASE',
+   no autovivification;
+   my $ret = 0;
+   while (1) {
+    ++$ret;
+    exit $ret;
+   }
+   exit $ret;
+  TESTCASE
+  "$base_desc postfix while (RT #99458)" => <<'  TESTCASE',
+   no autovivification;
+   my $ret = 0;
+   ++$ret && exit $ret while 1;
+   exit $ret;
+  TESTCASE
+  "$base_desc until loops" => <<'  TESTCASE',
+   no autovivification;
+   my $ret = 0;
+   until (0) {
+    ++$ret;
+    exit $ret;
+   }
+   exit $ret;
+  TESTCASE
+  "$base_desc postfix until" => <<'  TESTCASE',
+   no autovivification;
+   my $ret = 0;
+   ++$ret && exit $ret until 0;
+   exit $ret;
+  TESTCASE
+ );
+
+ for my $desc (keys %infinite_tests) {
+  my $code = $infinite_tests{$desc};
+  my $ret  = run_perl $code;
+  my $stat = $ret & 255;
+  $ret   >>= 8;
+  is $stat, 0, "$desc testcase did not crash";
+  is $ret,  1, "$desc compiled fine";
+ }
 }
 
 {