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');
44 open F, "<$file" or die "Cannot open $file: $!\n" ;
54 @prgs = (@prgs, $file, split "\n########\n", <F>) ;
61 print "1..", scalar(@prgs)-$files, "\n";
75 $switch =~ s/(-\S*[A-Z]\S*)/"$1"/ if $Is_VMS; # protect uc switches
77 my($prog,$expected) = split(/\nEXPECT\n/, $_);
78 if ( $prog =~ /--FILE--/) {
79 my(@files) = split(/\n--FILE--\s*([^\s\n]*)\s*\n/, $prog) ;
81 die "Internal error test $i didn't split into pairs, got " .
82 scalar(@files) . "[" . join("%%%%", @files) ."]\n"
85 my $filename = shift @files ;
86 my $code = shift @files ;
87 push @temps, $filename ;
88 if ($filename =~ m#(.*)/#) {
92 open F, ">$filename" or die "Cannot open $filename: $!\n" ;
94 close F or die "Cannot close $filename: $!\n";
97 $prog = shift @files ;
101 if ($^O eq 'MacOS') {
102 $prog =~ s|require "./abc(d)?";|require ":abc$1";|g;
103 $prog =~ s|"\."|":"|g;
106 open TEST, ">$tmpfile" or die "Cannot open >$tmpfile: $!";
109 open(STDERR, ">&STDOUT")
110 or die "Can't dup STDOUT->STDERR: $!;";
113 print TEST "\n#line 1\n"; # So the line numbers don't get messed up.
114 print TEST $prog,"\n";
115 close TEST or die "Cannot close $tmpfile: $!";
116 my $results = $Is_VMS ?
117 `./perl "-I../lib" $switch $tmpfile` :
119 `.\\perl -I../lib $switch $tmpfile` :
121 `perl -I../lib $switch $tmpfile` :
123 `$^X -I::lib $switch -MMac::err=unix $tmpfile` :
124 `./perl -I../lib $switch $tmpfile`;
126 $results =~ s/\n+$//;
127 # allow expected output to be written as if $prog is on STDIN
128 $results =~ s/tmp\d+/-/g;
130 # some tests will trigger VMS messages that won't be expected
131 $results =~ s/\n?%[A-Z]+-[SIWEF]-[A-Z]+,.*//;
133 # pipes double these sometimes
134 $results =~ s/\n\n/\n/g;
136 # bison says 'parse error' instead of 'syntax error',
137 # various yaccs may or may not capitalize 'syntax'.
138 $results =~ s/^(syntax|parse) error/syntax error/mig;
139 # allow all tests to run when there are leaks
140 $results =~ s/Scalars leaked: \d+\n//g;
143 if ($^O eq 'MacOS') {
144 $results =~ s|:abc\.pm\b|abc.pm|g;
145 $results =~ s|:abc(d)?\b|./abc$1|g;
148 $expected =~ s/\n+$//;
149 my $prefix = ($results =~ s#^PREFIX(\n|$)##) ;
150 # any special options? (OPTIONS foo bar zap)
151 my $option_regex = 0;
152 my $option_random = 0;
153 if ($expected =~ s/^OPTIONS? (.+)\n//) {
154 foreach my $option (split(' ', $1)) {
155 if ($option eq 'regex') { # allow regular expressions
158 elsif ($option eq 'random') { # all lines match, but in any order
162 die "$0: Unknown OPTION '$option'\n";
166 die "$0: can't have OPTION regex and random\n"
167 if $option_regex + option_random > 1;
168 if ( $results =~ s/^SKIPPED\n//) {
171 elsif ($option_random)
173 print "not " if !randomMatch($results, $expected);
175 elsif (($prefix && (( $option_regex && $results !~ /^$expected/) ||
176 (!$option_regex && $results !~ /^\Q$expected/))) or
177 (!$prefix && (( $option_regex && $results !~ /^$expected/) ||
178 (!$option_regex && $results ne $expected)))) {
179 print STDERR "PROG: $switch\n$prog\n";
180 print STDERR "EXPECTED:\n$expected\n";
181 print STDERR "GOT:\n$results\n";
184 print "ok ", ++$i, "\n";
188 { rmtree $_ if -d $_ }
194 my $expected = shift;
196 my @got = sort split "\n", $got ;
197 my @expected = sort split "\n", $expected ;
199 return "@got" eq "@expected";