1 # This code is used by lib/warnings.t and lib/feature.t
9 use File::Spec::Functions;
16 my $Is_MacOS = $^O eq 'MacOS';
17 my $tmpfile = "tmp0000";
18 1 while -e ++$tmpfile;
19 END { 1 while unlink $tmpfile }
25 { print "ARGV = [@ARGV]\n" ;
27 @w_files = map { s#^#:lib:$pragma_name:#; $_ } @ARGV
29 @w_files = map { s#^#./lib/$pragma_name/#; $_ } @ARGV
33 { @w_files = sort glob(catfile(curdir(), "lib", $pragma_name, "*")) }
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);
73 my($prog,$expected) = split(/\nEXPECT(?:\n|$)/, $_, 2);
75 my ($todo, $todo_reason);
76 $todo = $prog =~ s/^#\s*TODO(.*)\n//m and $todo_reason = $1;
77 if ( $prog =~ /--FILE--/) {
78 my(@files) = split(/\n--FILE--\s*([^\s\n]*)\s*\n/, $prog) ;
80 die "Internal error: test $_ didn't split into pairs, got " .
81 scalar(@files) . "[" . join("%%%%", @files) ."]\n"
84 my $filename = shift @files ;
85 my $code = shift @files ;
86 push @temps, $filename ;
87 if ($filename =~ m#(.*)/#) {
91 open F, ">$filename" or die "Cannot open $filename: $!\n" ;
93 close F or die "Cannot close $filename: $!\n";
96 $prog = shift @files ;
101 $prog =~ s|require "./abc(d)?";|require ":abc$1";|g;
102 $prog =~ s|"\."|":"|g;
105 open TEST, ">$tmpfile" or die "Cannot open >$tmpfile: $!";
108 open(STDERR, ">&STDOUT")
109 or die "Can't dup STDOUT->STDERR: $!;";
112 print TEST "\n#line 1\n"; # So the line numbers don't get messed up.
113 print TEST $prog,"\n";
114 close TEST or die "Cannot close $tmpfile: $!";
115 my $results = runperl( switches => [$switch], stderr => 1, progfile => $tmpfile );
117 $results =~ s/\n+$//;
118 # allow expected output to be written as if $prog is on STDIN
119 $results =~ s/tmp\d+/-/g;
121 # some tests will trigger VMS messages that won't be expected
122 $results =~ s/\n?%[A-Z]+-[SIWEF]-[A-Z]+,.*//;
124 # pipes double these sometimes
125 $results =~ s/\n\n/\n/g;
127 # bison says 'parse error' instead of 'syntax error',
128 # various yaccs may or may not capitalize 'syntax'.
129 $results =~ s/^(syntax|parse) error/syntax error/mig;
130 # allow all tests to run when there are leaks
131 $results =~ s/Scalars leaked: \d+\n//g;
135 $results =~ s|:abc\.pm\b|abc.pm|g;
136 $results =~ s|:abc(d)?\b|./abc$1|g;
139 $expected =~ s/\n+$//;
140 my $prefix = ($results =~ s#^PREFIX(\n|$)##) ;
141 # any special options? (OPTIONS foo bar zap)
142 my $option_regex = 0;
143 my $option_random = 0;
144 if ($expected =~ s/^OPTIONS? (.+)\n//) {
145 foreach my $option (split(' ', $1)) {
146 if ($option eq 'regex') { # allow regular expressions
149 elsif ($option eq 'random') { # all lines match, but in any order
153 die "$0: Unknown OPTION '$option'\n";
157 die "$0: can't have OPTION regex and random\n"
158 if $option_regex + $option_random > 1;
160 if ($results =~ s/^SKIPPED\n//) {
164 elsif ($option_random) {
165 $ok = randomMatch($results, $expected);
167 elsif ($option_regex) {
168 $ok = $results =~ /^$expected/;
171 $ok = $results =~ /^\Q$expected/;
174 $ok = $results eq $expected;
177 print_err_line( $switch, $prog, $expected, $results, $todo ) unless $ok;
179 our $TODO = $todo ? $todo_reason : 0;
185 { rmtree $_ if -d $_ }
191 my $expected = shift;
193 my @got = sort split "\n", $got ;
194 my @expected = sort split "\n", $expected ;
196 return "@got" eq "@expected";
201 my($switch, $prog, $expected, $results, $todo) = @_;
202 my $err_line = "PROG: $switch\n$prog\n" .
203 "EXPECTED:\n$expected\n" .
206 $err_line =~ s/^/# /mg;
207 print $err_line; # Harness can't filter it out from STDERR.
210 print STDERR $err_line;