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 $Is_NetWare = $^O eq 'NetWare';
17 my $Is_MacOS = $^O eq 'MacOS';
18 my $tmpfile = "tmp0000";
20 1 while -e ++$tmpfile;
21 END { if ($tmpfile) { 1 while unlink $tmpfile} }
29 my($prog,$expected) = split(/\nEXPECT\n/, $_);
30 if ( $prog =~ /--FILE--/) {
31 my(@files) = split(/\n--FILE--\s*([^\s\n]*)\s*\n/, $prog) ;
33 die "Internal error test $i didn't split into pairs, got " .
34 scalar(@files) . "[" . join("%%%%", @files) ."]\n"
37 my $filename = shift @files ;
38 my $code = shift @files ;
39 push @temps, $filename ;
40 open F, ">$filename" or die "Cannot open $filename: $!\n" ;
45 $prog = shift @files ;
47 open TEST, ">$tmpfile";
48 print TEST $prog,"\n";
50 my $results = $Is_VMS ?
51 `./perl $switch $tmpfile 2>&1` :
53 `.\\perl -I../lib $switch $tmpfile 2>&1` :
55 `perl -I../lib $switch $tmpfile 2>&1` :
57 `$^X -I::lib -MMac::err=unix $switch $tmpfile` :
58 `./perl $switch $tmpfile 2>&1`;
61 # allow expected output to be written as if $prog is on STDIN
62 $results =~ s/tmp\d+/-/g;
63 $results =~ s/\n%[A-Z]+-[SIWEF]-.*$// if $Is_VMS; # clip off DCL status msg
64 # bison says 'parse error' instead of 'syntax error',
65 # various yaccs may or may not capitalize 'syntax'.
66 $results =~ s/^(syntax|parse) error/syntax error/mig;
67 $expected =~ s/\n+$//;
68 my $prefix = ($results =~ s/^PREFIX\n//) ;
69 if ( $results =~ s/^SKIPPED\n//) {
72 elsif (($prefix and $results !~ /^\Q$expected/) or
73 (!$prefix and $results ne $expected)){
74 print STDERR "PROG: $switch\n$prog\n";
75 print STDERR "EXPECTED:\n$expected\n";
76 print STDERR "GOT:\n$results\n";
79 print "ok ", ++$i, "\n";
86 # Error - not predeclaring a sub
90 Number found where operator expected at - line 3, near "Fred 1"
91 (Do you need to predeclare Fred?)
92 syntax error at - line 3, near "Fred 1"
93 Execution of - aborted due to compilation errors.
96 # Error - not predeclaring a sub in time
101 Number found where operator expected at - line 3, near "Fred 1"
102 (Do you need to predeclare Fred?)
103 syntax error at - line 3, near "Fred 1"
104 BEGIN not safe after errors--compilation aborted at - line 4.
110 sub Fred { print $_[0] + $_[1], "\n" }
115 # override a built-in function
116 use subs qw( open ) ;
118 sub open { print $_[0] + $_[1], "\n" }
123 # override a built-in function, call after definition
124 use subs qw( open ) ;
125 sub open { print $_[0] + $_[1], "\n" }
131 # override a built-in function, call with ()
132 use subs qw( open ) ;
134 sub open { print $_[0] + $_[1], "\n" }
139 # override a built-in function, call with () after definition
140 use subs qw( open ) ;
141 sub open { print $_[0] + $_[1], "\n" }
151 use subs qw( Fred ) ;
153 sub Fred { print $_[0] + $_[1], "\n" }
158 # check that it isn't affected by block scope
160 use subs qw( Fred ) ;
163 sub Fred { print $_[0] + $_[1], "\n" }