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 if ( $prog =~ /--FILE--/) {
80 my(@files) = split(/\n--FILE--\s*([^\s\n]*)\s*\n/, $prog) ;
82 die "Internal error test $i didn't split into pairs, got " .
83 scalar(@files) . "[" . join("%%%%", @files) ."]\n"
86 my $filename = shift @files ;
87 my $code = shift @files ;
88 push @temps, $filename ;
89 if ($filename =~ m#(.*)/#) {
93 open F, ">$filename" or die "Cannot open $filename: $!\n" ;
95 close F or die "Cannot close $filename: $!\n";
98 $prog = shift @files ;
102 if ($^O eq 'MacOS') {
103 $prog =~ s|require "./abc(d)?";|require ":abc$1";|g;
104 $prog =~ s|"\."|":"|g;
107 open TEST, ">$tmpfile" or die "Cannot open >$tmpfile: $!";
110 open(STDERR, ">&STDOUT")
111 or die "Can't dup STDOUT->STDERR: $!;";
114 print TEST "\n#line 1\n"; # So the line numbers don't get messed up.
115 print TEST $prog,"\n";
116 close TEST or die "Cannot close $tmpfile: $!";
117 my $results = $Is_VMS ?
118 `./perl "-I../lib" $switch $tmpfile` :
120 `.\\perl -I../lib $switch $tmpfile` :
122 `perl -I../lib $switch $tmpfile` :
124 `$^X -I::lib $switch -MMac::err=unix $tmpfile` :
125 `./perl -I../lib $switch $tmpfile`;
127 $results =~ s/\n+$//;
128 # allow expected output to be written as if $prog is on STDIN
129 $results =~ s/tmp\d+/-/g;
131 # some tests will trigger VMS messages that won't be expected
132 $results =~ s/\n?%[A-Z]+-[SIWEF]-[A-Z]+,.*//;
134 # pipes double these sometimes
135 $results =~ s/\n\n/\n/g;
137 # bison says 'parse error' instead of 'syntax error',
138 # various yaccs may or may not capitalize 'syntax'.
139 $results =~ s/^(syntax|parse) error/syntax error/mig;
140 # allow all tests to run when there are leaks
141 $results =~ s/Scalars leaked: \d+\n//g;
144 if ($^O eq 'MacOS') {
145 $results =~ s|:abc\.pm\b|abc.pm|g;
146 $results =~ s|:abc(d)?\b|./abc$1|g;
149 $expected =~ s/\n+$//;
150 my $prefix = ($results =~ s#^PREFIX(\n|$)##) ;
151 # any special options? (OPTIONS foo bar zap)
152 my $option_regex = 0;
153 my $option_random = 0;
154 if ($expected =~ s/^OPTIONS? (.+)\n//) {
155 foreach my $option (split(' ', $1)) {
156 if ($option eq 'regex') { # allow regular expressions
159 elsif ($option eq 'random') { # all lines match, but in any order
163 die "$0: Unknown OPTION '$option'\n";
167 die "$0: can't have OPTION regex and random\n"
168 if $option_regex + option_random > 1;
169 if ( $results =~ s/^SKIPPED\n//) {
172 elsif ($option_random)
174 print "not " if !randomMatch($results, $expected);
176 elsif (($prefix && (( $option_regex && $results !~ /^$expected/) ||
177 (!$option_regex && $results !~ /^\Q$expected/))) or
178 (!$prefix && (( $option_regex && $results !~ /^$expected/) ||
179 (!$option_regex && $results ne $expected)))) {
180 print STDERR "PROG: $switch\n$prog\n";
181 print STDERR "EXPECTED:\n$expected\n";
182 print STDERR "GOT:\n$results\n";
185 print "ok ", ++$i, "\n";
189 { rmtree $_ if -d $_ }
195 my $expected = shift;
197 my @got = sort split "\n", $got ;
198 my @expected = sort split "\n", $expected ;
200 return "@got" eq "@expected";