6 $ENV{PERL5LIB} = '../lib';
7 require Config; import Config;
12 use File::Spec::Functions;
16 my $Is_MacOS = $^O eq 'MacOS';
17 my $tmpfile = "tmp0000";
18 1 while -e ++$tmpfile;
19 END { if ($tmpfile) { 1 while unlink $tmpfile} }
25 { print "ARGV = [@ARGV]\n" ;
27 @w_files = map { s#^#:lib:warnings:#; $_ } @ARGV
29 @w_files = map { s#^#./lib/warnings/#; $_ } @ARGV
33 { @w_files = sort glob(catfile(curdir(), "lib", "warnings", "*")) }
36 foreach my $file (@w_files) {
38 next if $file =~ /(~|\.orig|,v)$/;
39 next if $file =~ /perlio$/ && !(find PerlIO::Layer 'perlio');
42 open F, "<$file" or die "Cannot open $file: $!\n" ;
52 @prgs = (@prgs, $file, split "\n########\n", <F>) ;
59 plan tests => (scalar(@prgs)-$files);
75 my($prog,$expected) = split(/\nEXPECT\n/, $_);
76 my ($todo, $todo_reason);
77 $todo = $prog =~ s/^#\s*TODO(.*)\n//m and $todo_reason = $1;
78 if ( $prog =~ /--FILE--/) {
79 my(@files) = split(/\n--FILE--\s*([^\s\n]*)\s*\n/, $prog) ;
81 die "Internal error test $test 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 = runperl( switches => [$switch], stderr => 1, progfile => $tmpfile );
118 $results =~ s/\n+$//;
119 # allow expected output to be written as if $prog is on STDIN
120 $results =~ s/tmp\d+/-/g;
122 # some tests will trigger VMS messages that won't be expected
123 $results =~ s/\n?%[A-Z]+-[SIWEF]-[A-Z]+,.*//;
125 # pipes double these sometimes
126 $results =~ s/\n\n/\n/g;
128 # bison says 'parse error' instead of 'syntax error',
129 # various yaccs may or may not capitalize 'syntax'.
130 $results =~ s/^(syntax|parse) error/syntax error/mig;
131 # allow all tests to run when there are leaks
132 $results =~ s/Scalars leaked: \d+\n//g;
135 if ($^O eq 'MacOS') {
136 $results =~ s|:abc\.pm\b|abc.pm|g;
137 $results =~ s|:abc(d)?\b|./abc$1|g;
140 $expected =~ s/\n+$//;
141 my $prefix = ($results =~ s#^PREFIX(\n|$)##) ;
142 # any special options? (OPTIONS foo bar zap)
143 my $option_regex = 0;
144 my $option_random = 0;
145 if ($expected =~ s/^OPTIONS? (.+)\n//) {
146 foreach my $option (split(' ', $1)) {
147 if ($option eq 'regex') { # allow regular expressions
150 elsif ($option eq 'random') { # all lines match, but in any order
154 die "$0: Unknown OPTION '$option'\n";
158 die "$0: can't have OPTION regex and random\n"
159 if $option_regex + option_random > 1;
161 if ( $results =~ s/^SKIPPED\n//) {
164 elsif ($option_random)
166 $ok = randomMatch($results, $expected);
168 elsif (($prefix && (( $option_regex && $results !~ /^$expected/) ||
169 (!$option_regex && $results !~ /^\Q$expected/))) or
170 (!$prefix && (( $option_regex && $results !~ /^$expected/) ||
171 (!$option_regex && $results ne $expected)))) {
172 my $err_line = "PROG: $switch\n$prog\n" .
173 "EXPECTED:\n$expected\n" .
176 $err_line =~ s/^/# /mg;
177 print $err_line; # Harness can't filter it out from STDERR.
180 print STDERR $err_line;
185 $TODO = $todo ? $todo_reason : 0;
191 { rmtree $_ if -d $_ }
197 my $expected = shift;
199 my @got = sort split "\n", $got ;
200 my @expected = sort split "\n", $expected ;
202 return "@got" eq "@expected";