From 24d0fc42f3cde6d97ff49e299caa014144e156ef Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Tue, 13 Oct 2009 14:33:38 +0100 Subject: Move tests for $[ from comp/parser.t to op/array_base.t Tests in t/comp/ are too early to rely on pragmata working. --- t/comp/parser.t | 36 +----------------------------------- t/op/array_base.t | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 35 deletions(-) create mode 100644 t/op/array_base.t (limited to 't') diff --git a/t/comp/parser.t b/t/comp/parser.t index d0e7f5d62e..eed0f1873c 100644 --- a/t/comp/parser.t +++ b/t/comp/parser.t @@ -3,7 +3,7 @@ # Checks if the parser behaves correctly in edge cases # (including weird syntax errors) -print "1..112\n"; +print "1..104\n"; sub failed { my ($got, $expected, $name) = @_; @@ -195,16 +195,6 @@ EOF like( $@, qr/syntax error/, "use without body" ); } -# Bug #27024 -{ - # this used to segfault (because $[=1 is optimized away to a null block) - my $x; - $[ = 1 while $x; - $test = $test + 1; - print "ok $test\n"; - $[ = 0; # restore the original value for less side-effects -} - # [perl #2738] perl segfautls on input { eval q{ sub _ <> {} }; @@ -217,30 +207,6 @@ EOF like($@, qr/Illegal declaration of subroutine main::_/, "__FILE__ as prototype"); } -# [perl #36313] perl -e "1for$[=0" crash -{ - my $x; - $x = 1 for ($[) = 0; - $test = $test + 1; - print "ok $test - optimized assignment to \$[ used to segfault in list context\n"; - if ($[ = 0) { $x = 1 } - $test = $test + 1; - print "ok $test - optimized assignment to \$[ used to segfault in scalar context\n"; - $x = ($[=2.4); - is($x, 2, 'scalar assignment to $[ behaves like other variables'); - $x = (($[) = 0); - is($x, 1, 'list assignment to $[ behaves like other variables'); - $x = eval q{ ($[, $x) = (0) }; - like($@, qr/That use of \$\[ is unsupported/, - 'cannot assign to $[ in a list'); - eval q{ ($[) = (0, 1) }; - like($@, qr/That use of \$\[ is unsupported/, - 'cannot assign list of >1 elements to $['); - eval q{ ($[) = () }; - like($@, qr/That use of \$\[ is unsupported/, - 'cannot assign list of <1 elements to $['); -} - # tests for "Bad name" eval q{ foo::$bar }; like( $@, qr/Bad name after foo::/, 'Bad name after foo::' ); diff --git a/t/op/array_base.t b/t/op/array_base.t new file mode 100644 index 0000000000..98047901af --- /dev/null +++ b/t/op/array_base.t @@ -0,0 +1,38 @@ +#!perl -w +use strict; + +require './test.pl'; + +plan (tests => 8); +no warnings 'deprecated'; + +# Bug #27024 +{ + # this used to segfault (because $[=1 is optimized away to a null block) + my $x; + $[ = 1 while $x; + pass('#27204'); + $[ = 0; # restore the original value for less side-effects +} + +# [perl #36313] perl -e "1for$[=0" crash +{ + my $x; + $x = 1 for ($[) = 0; + pass('optimized assignment to $[ used to segfault in list context'); + if ($[ = 0) { $x = 1 } + pass('optimized assignment to $[ used to segfault in scalar context'); + $x = ($[=2.4); + is($x, 2, 'scalar assignment to $[ behaves like other variables'); + $x = (($[) = 0); + is($x, 1, 'list assignment to $[ behaves like other variables'); + $x = eval q{ ($[, $x) = (0) }; + like($@, qr/That use of \$\[ is unsupported/, + 'cannot assign to $[ in a list'); + eval q{ ($[) = (0, 1) }; + like($@, qr/That use of \$\[ is unsupported/, + 'cannot assign list of >1 elements to $['); + eval q{ ($[) = () }; + like($@, qr/That use of \$\[ is unsupported/, + 'cannot assign list of <1 elements to $['); +} -- cgit v1.2.1