From: Vincent Pit Date: Mon, 13 Oct 2014 13:05:15 +0000 (-0300) Subject: Test that infinite loops don't crash X-Git-Tag: rt99458~1 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2Fautovivification.git;a=commitdiff_plain;h=c2237219516974eb5eba3b1a71a4b1e49d72c4e0 Test that infinite loops don't crash --- diff --git a/t/43-peep.t b/t/43-peep.t index 5050821..a91b5f4 100644 --- a/t/43-peep.t +++ b/t/43-peep.t @@ -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 + 1 * 2 + 5 * 3; { my $desc = 'peephole optimization of conditionals'; @@ -108,26 +113,26 @@ 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 %infinite_tests = ( + 'peephole optimization of infinite 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 + ); + + 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"; + } } {