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 $tmpfile = "tmp0000";
17 1 while -f ++$tmpfile;
18 END { if ($tmpfile) { 1 while unlink $tmpfile} }
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 open TEST, ">$tmpfile";
45 print TEST $prog,"\n";
47 my $results = $Is_VMS ?
48 `MCR $^X $switch $tmpfile` :
49 `sh -c './perl $switch $tmpfile' 2>&1`;
52 # allow expected output to be written as if $prog is on STDIN
53 $results =~ s/tmp\d+/-/g;
54 $results =~ s/\n%[A-Z]+-[SIWEF]-.*$// if $Is_VMS; # clip off DCL status msg
55 $expected =~ s/\n+$//;
56 my $prefix = ($results =~ s/^PREFIX\n//) ;
57 if ( $results =~ s/^SKIPPED\n//) {
60 elsif (($prefix and $results !~ /^\Q$expected/) or
61 (!$prefix and $results ne $expected)){
62 print STDERR "PROG: $switch\n$prog\n";
63 print STDERR "EXPECTED:\n$expected\n";
64 print STDERR "GOT:\n$results\n";
67 print "ok ", ++$i, "\n";
74 # Error - not predeclaring a sub
78 Number found where operator expected at - line 3, near "Fred 1"
79 (Do you need to predeclare Fred?)
80 syntax error at - line 3, near "Fred 1"
81 Execution of - aborted due to compilation errors.
84 # Error - not predeclaring a sub in time
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.
98 sub Fred { print $_[0] + $_[1], "\n" }
103 # override a built-in function
104 use subs qw( open ) ;
106 sub open { print $_[0] + $_[1], "\n" }
115 use subs qw( Fred ) ;
117 sub Fred { print $_[0] + $_[1], "\n" }
122 # check that it isn't affected by block scope
124 use subs qw( Fred ) ;
127 sub Fred { print $_[0] + $_[1], "\n" }