6 $ENV{PERL5LIB} = '../lib';
7 require Config; import Config;
11 use File::Spec::Functions;
15 my $Is_VMS = $^O eq 'VMS';
16 my $Is_MSWin32 = $^O eq 'MSWin32';
17 my $Is_NetWare = $^O eq 'NetWare';
18 my $Is_MacOS = $^O eq 'MacOS';
19 my $tmpfile = "tmp0000";
21 1 while -e ++$tmpfile;
22 END { if ($tmpfile) { 1 while unlink $tmpfile} }
28 { print "ARGV = [@ARGV]\n" ;
30 @w_files = map { s#^#:lib:warnings:#; $_ } @ARGV
32 @w_files = map { s#^#./lib/warnings/#; $_ } @ARGV
36 { @w_files = sort glob(catfile(curdir(), "lib", "warnings", "*")) }
39 foreach my $file (@w_files) {
41 next if $file =~ /(~|\.orig|,v)$/;
42 next if $file =~ /perlio$/ && !(find PerlIO::Layer 'perlio');
45 open F, "<$file" or die "Cannot open $file: $!\n" ;
55 @prgs = (@prgs, $file, split "\n########\n", <F>) ;
62 print "1.." . (scalar(@prgs)-$files) . "\n";
76 $switch =~ s/(-\S*[A-Z]\S*)/"$1"/ if $Is_VMS; # protect uc switches
78 my($prog,$expected) = split(/\nEXPECT\n/, $_);
79 my ($todo, $todo_reason);
80 $todo = $prog =~ s/^#\s*TODO(.*)\n//m and $todo_reason = $1;
81 if ( $prog =~ /--FILE--/) {
82 my(@files) = split(/\n--FILE--\s*([^\s\n]*)\s*\n/, $prog) ;
84 die "Internal error test $i didn't split into pairs, got " .
85 scalar(@files) . "[" . join("%%%%", @files) ."]\n"
88 my $filename = shift @files ;
89 my $code = shift @files ;
90 push @temps, $filename ;
91 if ($filename =~ m#(.*)/#) {
95 open F, ">$filename" or die "Cannot open $filename: $!\n" ;
97 close F or die "Cannot close $filename: $!\n";
100 $prog = shift @files ;
104 if ($^O eq 'MacOS') {
105 $prog =~ s|require "./abc(d)?";|require ":abc$1";|g;
106 $prog =~ s|"\."|":"|g;
109 open TEST, ">$tmpfile" or die "Cannot open >$tmpfile: $!";
112 open(STDERR, ">&STDOUT")
113 or die "Can't dup STDOUT->STDERR: $!;";
116 print TEST "\n#line 1\n"; # So the line numbers don't get messed up.
117 print TEST $prog,"\n";
118 close TEST or die "Cannot close $tmpfile: $!";
119 my $results = $Is_VMS ?
120 `./perl "-I../lib" $switch $tmpfile` :
122 `.\\perl -I../lib $switch $tmpfile` :
124 `perl -I../lib $switch $tmpfile` :
126 `$^X -I::lib $switch -MMac::err=unix $tmpfile` :
127 `./perl -I../lib $switch $tmpfile`;
129 $results =~ s/\n+$//;
130 # allow expected output to be written as if $prog is on STDIN
131 $results =~ s/tmp\d+/-/g;
133 # some tests will trigger VMS messages that won't be expected
134 $results =~ s/\n?%[A-Z]+-[SIWEF]-[A-Z]+,.*//;
136 # pipes double these sometimes
137 $results =~ s/\n\n/\n/g;
139 # bison says 'parse error' instead of 'syntax error',
140 # various yaccs may or may not capitalize 'syntax'.
141 $results =~ s/^(syntax|parse) error/syntax error/mig;
142 # allow all tests to run when there are leaks
143 $results =~ s/Scalars leaked: \d+\n//g;
146 if ($^O eq 'MacOS') {
147 $results =~ s|:abc\.pm\b|abc.pm|g;
148 $results =~ s|:abc(d)?\b|./abc$1|g;
151 $expected =~ s/\n+$//;
152 my $prefix = ($results =~ s#^PREFIX(\n|$)##) ;
153 # any special options? (OPTIONS foo bar zap)
154 my $option_regex = 0;
155 my $option_random = 0;
156 if ($expected =~ s/^OPTIONS? (.+)\n//) {
157 foreach my $option (split(' ', $1)) {
158 if ($option eq 'regex') { # allow regular expressions
161 elsif ($option eq 'random') { # all lines match, but in any order
165 die "$0: Unknown OPTION '$option'\n";
169 die "$0: can't have OPTION regex and random\n"
170 if $option_regex + option_random > 1;
171 if ( $results =~ s/^SKIPPED\n//) {
174 elsif ($option_random)
176 print "not " if !randomMatch($results, $expected);
178 elsif (($prefix && (( $option_regex && $results !~ /^$expected/) ||
179 (!$option_regex && $results !~ /^\Q$expected/))) or
180 (!$prefix && (( $option_regex && $results !~ /^$expected/) ||
181 (!$option_regex && $results ne $expected)))) {
182 my $err_line = "PROG: $switch\n$prog\n" .
183 "EXPECTED:\n$expected\n" .
186 $err_line =~ s/^/# /mg;
187 print $err_line; # Harness can't filter it out from STDERR.
190 print STDERR $err_line;
195 print " # TODO$todo_reason" if $todo;
200 { rmtree $_ if -d $_ }
206 my $expected = shift;
208 my @got = sort split "\n", $got ;
209 my @expected = sort split "\n", $expected ;
211 return "@got" eq "@expected";