3 # Note : we're not using t/test.pl here, because we would need
4 # fresh_perl_is, and fresh_perl_is uses a closure -- a special
5 # case of what this program tests for.
9 $Is_VMS = $^O eq 'VMS';
10 $Is_MSWin32 = $^O eq 'MSWin32';
11 $Is_MacOS = $^O eq 'MacOS';
12 $Is_NetWare = $^O eq 'NetWare';
13 $ENV{PERL5LIB} = "../lib" unless $Is_VMS;
18 @prgs = split "\n########\n", <DATA>;
19 print "1..", 6 + scalar @prgs, "\n";
21 $tmpfile = "asubtmp000";
22 1 while -f ++$tmpfile;
23 END { if ($tmpfile) { 1 while unlink $tmpfile; } }
30 my($prog,$expected) = split(/\nEXPECT\n/, $_);
31 open TEST, ">$tmpfile";
33 close TEST or die "Could not close: $!";
34 my $results = $Is_VMS ?
35 `$^X "-I[-.lib]" $switch $tmpfile 2>&1` :
37 `.\\perl -I../lib $switch $tmpfile 2>&1` :
39 `$^X -I::lib $switch $tmpfile` :
41 `perl -I../lib $switch $tmpfile 2>&1` :
42 `./perl $switch $tmpfile 2>&1`;
45 # allow expected output to be written as if $prog is on STDIN
46 $results =~ s/runltmp\d+/-/g;
47 $results =~ s/\n%[A-Z]+-[SIWEF]-.*$// if $Is_VMS; # clip off DCL status msg
48 $expected =~ s/\n+$//;
49 if ($results ne $expected) {
50 print STDERR "PROG: $switch\n$prog\n";
51 print STDERR "EXPECTED:\n$expected\n";
52 print STDERR "GOT:\n$results\n";
55 print "ok ", ++$i, "\n";
58 sub test_invalid_decl {
59 my ($code,$todo) = @_;
62 if ($@ =~ /^Illegal declaration of anonymous subroutine at/) {
63 print "ok ", ++$i, " - '$code' is illegal$todo\n";
65 print "not ok ", ++$i, " - '$code' is illegal$todo\n# GOT: $@";
69 test_invalid_decl('sub;');
70 test_invalid_decl('sub ($) ;');
71 test_invalid_decl('{ $x = sub }');
72 test_invalid_decl('sub ($) && 1');
73 test_invalid_decl('sub ($) : lvalue;',' # TODO');
75 eval "sub #foo\n{print 1}";
77 print "ok ", ++$i, "\n";
79 print "not ok ", ++$i, "\n# GOT: $@";
96 my $dummy = $n; # eval can't close on $n without internal reference
109 eval 'sub { print $n }';
121 eval 'sub Y { my $p = shift; $p->() }';
129 print sub { return "ok 1\n" } -> ();