diff options
author | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2002-10-29 20:37:31 +0000 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2002-10-29 20:37:31 +0000 |
commit | 904d85c5b9ccc833788234557fda3bc74a77ca8b (patch) | |
tree | d3a173b0ef63342d042d4082a467b71e0c32401f /t | |
parent | b8370f2a62ce28c9808787355d168ac28a1aaa1c (diff) | |
download | perl-904d85c5b9ccc833788234557fda3bc74a77ca8b.tar.gz |
Partial fix of bug [perl #17589] : prevent the parser to
segfault when encountering the erroneous construct "sub;".
p4raw-id: //depot/perl@18072
Diffstat (limited to 't')
-rwxr-xr-x | t/op/anonsub.t | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/t/op/anonsub.t b/t/op/anonsub.t index 893a72671c..ddfcd4795d 100755 --- a/t/op/anonsub.t +++ b/t/op/anonsub.t @@ -1,5 +1,9 @@ #!./perl +# Note : we're not using t/test.pl here, because we would need +# fresh_perl_is, and fresh_perl_is uses a closure -- a special +# case of what this program tests for. + chdir 't' if -d 't'; @INC = '../lib'; $Is_VMS = $^O eq 'VMS'; @@ -12,7 +16,7 @@ $|=1; undef $/; @prgs = split "\n########\n", <DATA>; -print "1..", scalar @prgs, "\n"; +print "1..", 6 + scalar @prgs, "\n"; $tmpfile = "asubtmp000"; 1 while -f ++$tmpfile; @@ -51,6 +55,30 @@ for (@prgs){ print "ok ", ++$i, "\n"; } +sub test_invalid_decl { + my ($code,$todo) = @_; + $todo //= ''; + eval $code; + if ($@ =~ /^Illegal declaration of anonymous subroutine at/) { + print "ok ", ++$i, " - '$code' is illegal$todo\n"; + } else { + print "not ok ", ++$i, " - '$code' is illegal$todo\n# GOT: $@"; + } +} + +test_invalid_decl('sub;'); +test_invalid_decl('sub ($) ;'); +test_invalid_decl('{ $x = sub }'); +test_invalid_decl('sub ($) && 1'); +test_invalid_decl('sub ($) : lvalue;',' # TODO'); + +eval "sub #foo\n{print 1}"; +if ($@ eq '') { + print "ok ", ++$i, "\n"; +} else { + print "not ok ", ++$i, "\n# GOT: $@"; +} + __END__ sub X { my $n = "ok 1\n"; |