X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fop%2Fanonsub.t;h=ddfcd4795d334a6e04464aa7f42b9a1b55837383;hb=e081bb54e0eecfb962e7f0cfd84fcbdb2683d54d;hp=fef40f935a3161a78e64187e4b82d21efd3cacbe;hpb=16920d4e7955f05583cb8e0e238058b2a6125125;p=p5sagit%2Fp5-mst-13.2.git diff --git a/t/op/anonsub.t b/t/op/anonsub.t index fef40f9..ddfcd47 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", ; -print "1..", scalar @prgs, "\n"; +print "1..", 6 + scalar @prgs, "\n"; $tmpfile = "asubtmp000"; 1 while -f ++$tmpfile; @@ -26,7 +30,7 @@ for (@prgs){ my($prog,$expected) = split(/\nEXPECT\n/, $_); open TEST, ">$tmpfile"; print TEST "$prog\n"; - close TEST; + close TEST or die "Could not close: $!"; my $results = $Is_VMS ? `MCR $^X "-I[-.lib]" $switch $tmpfile 2>&1` : $Is_MSWin32 ? @@ -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"; @@ -98,7 +126,6 @@ X(); EXPECT ok 1 ######## -package; print sub { return "ok 1\n" } -> (); EXPECT ok 1