6 $ENV{PERL5LIB} = '../lib';
12 my @prgs = split "\n########\n", <DATA>;
13 print "1..", scalar @prgs, "\n";
15 my $Is_VMS = $^O eq 'VMS';
16 my $Is_MSWin32 = $^O eq 'MSWin32';
17 my $Is_NetWare = $^O eq 'NetWare';
26 my($prog,$expected) = split(/\nEXPECT\n/, $_);
27 if ( $prog =~ /--FILE--/) {
28 my(@files) = split(/\n--FILE--\s*([^\s\n]*)\s*\n/, $prog) ;
30 die "Internal error test $i didn't split into pairs, got " .
31 scalar(@files) . "[" . join("%%%%", @files) ."]\n"
34 my $filename = shift @files ;
35 my $code = shift @files ;
36 push @temps, $filename ;
37 open F, ">$filename" or die "Cannot open $filename: $!\n" ;
42 $prog = shift @files ;
44 my $tmpfile = tempfile();
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` :
53 `perl -I../lib $switch $tmpfile 2>&1` :
54 `./perl $switch $tmpfile 2>&1`;
57 # allow expected output to be written as if $prog is on STDIN
58 $results =~ s/tmp\d+[A-Z][A-Z]?/-/g;
59 $results =~ s/\n%[A-Z]+-[SIWEF]-.*$// if $Is_VMS; # clip off DCL status msg
60 # bison says 'parse error' instead of 'syntax error',
61 # various yaccs may or may not capitalize 'syntax'.
62 $results =~ s/^(syntax|parse) error/syntax error/mig;
63 $expected =~ s/\n+$//;
64 my $prefix = ($results =~ s/^PREFIX\n//) ;
65 if ( $results =~ s/^SKIPPED\n//) {
68 elsif (($prefix and $results !~ /^\Q$expected/) or
69 (!$prefix and $results ne $expected)){
70 print STDERR "PROG: $switch\n$prog\n";
71 print STDERR "EXPECTED:\n$expected\n";
72 print STDERR "GOT:\n$results\n";
75 print "ok ", ++$i, "\n";
82 # Error - not predeclaring a sub
86 Number found where operator expected at - line 3, near "Fred 1"
87 (Do you need to predeclare Fred?)
88 syntax error at - line 3, near "Fred 1"
89 Execution of - aborted due to compilation errors.
92 # Error - not predeclaring a sub in time
97 Number found where operator expected at - line 3, near "Fred 1"
98 (Do you need to predeclare Fred?)
99 syntax error at - line 3, near "Fred 1"
100 BEGIN not safe after errors--compilation aborted at - line 4.
106 sub Fred { print $_[0] + $_[1], "\n" }
111 # override a built-in function
112 use subs qw( open ) ;
114 sub open { print $_[0] + $_[1], "\n" }
119 # override a built-in function, call after definition
120 use subs qw( open ) ;
121 sub open { print $_[0] + $_[1], "\n" }
127 # override a built-in function, call with ()
128 use subs qw( open ) ;
130 sub open { print $_[0] + $_[1], "\n" }
135 # override a built-in function, call with () after definition
136 use subs qw( open ) ;
137 sub open { print $_[0] + $_[1], "\n" }
147 use subs qw( Fred ) ;
149 sub Fred { print $_[0] + $_[1], "\n" }
154 # check that it isn't affected by block scope
156 use subs qw( Fred ) ;
159 sub Fred { print $_[0] + $_[1], "\n" }