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 $tmpfile = "tmp0000";
19 1 while -f ++$tmpfile;
20 END { if ($tmpfile) { 1 while unlink $tmpfile} }
28 my($prog,$expected) = split(/\nEXPECT\n/, $_);
29 if ( $prog =~ /--FILE--/) {
30 my(@files) = split(/\n--FILE--\s*([^\s\n]*)\s*\n/, $prog) ;
32 die "Internal error test $i didn't split into pairs, got " .
33 scalar(@files) . "[" . join("%%%%", @files) ."]\n"
36 my $filename = shift @files ;
37 my $code = shift @files ;
38 push @temps, $filename ;
39 open F, ">$filename" or die "Cannot open $filename: $!\n" ;
44 $prog = shift @files ;
46 open TEST, ">$tmpfile";
47 print TEST $prog,"\n";
49 my $results = $Is_VMS ?
50 `./perl $switch $tmpfile 2>&1` :
52 `.\\perl -I../lib $switch $tmpfile 2>&1` :
54 `perl -I../lib $switch $tmpfile 2>&1` :
56 `$^X -I::lib -MMac::err=unix $switch $tmpfile` :
57 `./perl $switch $tmpfile 2>&1`;
60 # allow expected output to be written as if $prog is on STDIN
61 $results =~ s/tmp\d+/-/g;
62 $results =~ s/\n%[A-Z]+-[SIWEF]-.*$// if $Is_VMS; # clip off DCL status msg
63 # bison says 'parse error' instead of 'syntax error',
64 # various yaccs may or may not capitalize 'syntax'.
65 $results =~ s/^(syntax|parse) error/syntax error/mig;
66 $expected =~ s/\n+$//;
67 my $prefix = ($results =~ s/^PREFIX\n//) ;
68 if ( $results =~ s/^SKIPPED\n//) {
71 elsif (($prefix and $results !~ /^\Q$expected/) or
72 (!$prefix and $results ne $expected)){
73 print STDERR "PROG: $switch\n$prog\n";
74 print STDERR "EXPECTED:\n$expected\n";
75 print STDERR "GOT:\n$results\n";
78 print "ok ", ++$i, "\n";
85 # Error - not predeclaring a sub
89 Number found where operator expected at - line 3, near "Fred 1"
90 (Do you need to predeclare Fred?)
91 syntax error at - line 3, near "Fred 1"
92 Execution of - aborted due to compilation errors.
95 # Error - not predeclaring a sub in time
100 Number found where operator expected at - line 3, near "Fred 1"
101 (Do you need to predeclare Fred?)
102 syntax error at - line 3, near "Fred 1"
103 BEGIN not safe after errors--compilation aborted at - line 4.
109 sub Fred { print $_[0] + $_[1], "\n" }
114 # override a built-in function
115 use subs qw( open ) ;
117 sub open { print $_[0] + $_[1], "\n" }
122 # override a built-in function, call after definition
123 use subs qw( open ) ;
124 sub open { print $_[0] + $_[1], "\n" }
130 # override a built-in function, call with ()
131 use subs qw( open ) ;
133 sub open { print $_[0] + $_[1], "\n" }
138 # override a built-in function, call with () after definition
139 use subs qw( open ) ;
140 sub open { print $_[0] + $_[1], "\n" }
150 use subs qw( Fred ) ;
152 sub Fred { print $_[0] + $_[1], "\n" }
157 # check that it isn't affected by block scope
159 use subs qw( Fred ) ;
162 sub Fred { print $_[0] + $_[1], "\n" }