6 $ENV{PERL5LIB} = '../lib';
11 my @prgs = split "\n########\n", <DATA>;
12 print "1..", scalar @prgs, "\n";
14 my $Is_VMS = $^O eq 'VMS';
15 my $Is_MSWin32 = $^O eq 'MSWin32';
16 my $tmpfile = "tmp0000";
18 1 while -f ++$tmpfile;
19 END { if ($tmpfile) { 1 while unlink $tmpfile} }
27 my($prog,$expected) = split(/\nEXPECT\n/, $_);
28 if ( $prog =~ /--FILE--/) {
29 my(@files) = split(/\n--FILE--\s*([^\s\n]*)\s*\n/, $prog) ;
31 die "Internal error test $i didn't split into pairs, got " .
32 scalar(@files) . "[" . join("%%%%", @files) ."]\n"
35 my $filename = shift @files ;
36 my $code = shift @files ;
37 push @temps, $filename ;
38 open F, ">$filename" or die "Cannot open $filename: $!\n" ;
43 $prog = shift @files ;
45 open TEST, ">$tmpfile";
46 print TEST $prog,"\n";
48 my $results = $Is_VMS ?
49 `./perl $switch $tmpfile 2>&1` :
51 `.\\perl -I../lib $switch $tmpfile 2>&1` :
52 `./perl $switch $tmpfile 2>&1`;
55 # allow expected output to be written as if $prog is on STDIN
56 $results =~ s/tmp\d+/-/g;
57 $results =~ s/\n%[A-Z]+-[SIWEF]-.*$// if $Is_VMS; # clip off DCL status msg
58 # bison says 'parse error' instead of 'syntax error',
59 # various yaccs may or may not capitalize 'syntax'.
60 $results =~ s/^(syntax|parse) error/syntax error/mig;
61 $expected =~ s/\n+$//;
62 my $prefix = ($results =~ s/^PREFIX\n//) ;
63 if ( $results =~ s/^SKIPPED\n//) {
66 elsif (($prefix and $results !~ /^\Q$expected/) or
67 (!$prefix and $results ne $expected)){
68 print STDERR "PROG: $switch\n$prog\n";
69 print STDERR "EXPECTED:\n$expected\n";
70 print STDERR "GOT:\n$results\n";
73 print "ok ", ++$i, "\n";
80 # Error - not predeclaring a sub
84 Number found where operator expected at - line 3, near "Fred 1"
85 (Do you need to predeclare Fred?)
86 syntax error at - line 3, near "Fred 1"
87 Execution of - aborted due to compilation errors.
90 # Error - not predeclaring a sub in time
95 Number found where operator expected at - line 3, near "Fred 1"
96 (Do you need to predeclare Fred?)
97 syntax error at - line 3, near "Fred 1"
98 BEGIN not safe after errors--compilation aborted at - line 4.
104 sub Fred { print $_[0] + $_[1], "\n" }
109 # override a built-in function
110 use subs qw( open ) ;
112 sub open { print $_[0] + $_[1], "\n" }
117 # override a built-in function, call after definition
118 use subs qw( open ) ;
119 sub open { print $_[0] + $_[1], "\n" }
125 # override a built-in function, call with ()
126 use subs qw( open ) ;
128 sub open { print $_[0] + $_[1], "\n" }
133 # override a built-in function, call with () after definition
134 use subs qw( open ) ;
135 sub open { print $_[0] + $_[1], "\n" }
145 use subs qw( Fred ) ;
147 sub Fred { print $_[0] + $_[1], "\n" }
152 # check that it isn't affected by block scope
154 use subs qw( Fred ) ;
157 sub Fred { print $_[0] + $_[1], "\n" }