1 # This code is used by lib/warnings.t and lib/feature.t
9 use File::Spec::Functions;
17 my $Is_MacOS = $^O eq 'MacOS';
18 my $tmpfile = tempfile();
24 { print "ARGV = [@ARGV]\n" ;
26 @w_files = map { s#^#:lib:$pragma_name:#; $_ } @ARGV
28 @w_files = map { s#^#./lib/$pragma_name/#; $_ } @ARGV
32 { @w_files = sort glob(catfile(curdir(), "lib", $pragma_name, "*")) }
35 foreach my $file (@w_files) {
37 next if $file =~ /(~|\.orig|,v)$/;
38 next if $file =~ /perlio$/ && !(find PerlIO::Layer 'perlio');
41 open F, "<$file" or die "Cannot open $file: $!\n" ;
51 @prgs = (@prgs, $file, split "\n########\n", <F>) ;
58 plan tests => (scalar(@prgs)-$files);
72 my($prog,$expected) = split(/\nEXPECT(?:\n|$)/, $_, 2);
75 foreach my $what (qw(skip todo)) {
76 $prog =~ s/^#\s*\U$what\E\s*(.*)\n//m and $reason{$what} = $1;
77 # If the SKIP reason starts ? then it's taken as a code snippet to
78 # evaluate. This provides the flexibility to have conditional SKIPs
79 if ($reason{$what} && $reason{$what} =~ s/^\?//) {
80 my $temp = eval $reason{$what};
82 die "# In \U$what\E code reason:\n# $reason{$what}\n$@";
84 $reason{$what} = $temp;
88 if ( $prog =~ /--FILE--/) {
89 my(@files) = split(/\n--FILE--\s*([^\s\n]*)\s*\n/, $prog) ;
91 die "Internal error: test $_ didn't split into pairs, got " .
92 scalar(@files) . "[" . join("%%%%", @files) ."]\n"
95 my $filename = shift @files ;
96 my $code = shift @files ;
97 push @temps, $filename ;
98 if ($filename =~ m#(.*)/#) {
100 push(@temp_path, $1);
102 open F, ">$filename" or die "Cannot open $filename: $!\n" ;
104 close F or die "Cannot close $filename: $!\n";
107 $prog = shift @files ;
112 $prog =~ s|require "./abc(d)?";|require ":abc$1";|g;
113 $prog =~ s|"\."|":"|g;
116 open TEST, ">$tmpfile" or die "Cannot open >$tmpfile: $!";
119 open(STDERR, ">&STDOUT")
120 or die "Can't dup STDOUT->STDERR: $!;";
123 print TEST "\n#line 1\n"; # So the line numbers don't get messed up.
124 print TEST $prog,"\n";
125 close TEST or die "Cannot close $tmpfile: $!";
126 my $results = runperl( switches => [$switch], stderr => 1, progfile => $tmpfile );
128 $results =~ s/\n+$//;
129 # allow expected output to be written as if $prog is on STDIN
130 $results =~ s/$::tempfile_regexp/-/g;
132 # some tests will trigger VMS messages that won't be expected
133 $results =~ s/\n?%[A-Z]+-[SIWEF]-[A-Z]+,.*//;
135 # pipes double these sometimes
136 $results =~ s/\n\n/\n/g;
138 # bison says 'parse error' instead of 'syntax error',
139 # various yaccs may or may not capitalize 'syntax'.
140 $results =~ s/^(syntax|parse) error/syntax error/mig;
141 # allow all tests to run when there are leaks
142 $results =~ s/Scalars leaked: \d+\n//g;
146 $results =~ s|:abc\.pm\b|abc.pm|g;
147 $results =~ s|:abc(d)?\b|./abc$1|g;
150 $expected =~ s/\n+$//;
151 my $prefix = ($results =~ s#^PREFIX(\n|$)##) ;
152 # any special options? (OPTIONS foo bar zap)
153 my $option_regex = 0;
154 my $option_random = 0;
155 if ($expected =~ s/^OPTIONS? (.+)\n//) {
156 foreach my $option (split(' ', $1)) {
157 if ($option eq 'regex') { # allow regular expressions
160 elsif ($option eq 'random') { # all lines match, but in any order
164 die "$0: Unknown OPTION '$option'\n";
168 die "$0: can't have OPTION regex and random\n"
169 if $option_regex + $option_random > 1;
171 if ($results =~ s/^SKIPPED\n//) {
175 elsif ($option_random) {
176 $ok = randomMatch($results, $expected);
178 elsif ($option_regex) {
179 $ok = $results =~ /^$expected/;
182 $ok = $results =~ /^\Q$expected/;
185 $ok = $results eq $expected;
188 local $::TODO = $reason{todo};
189 print_err_line( $switch, $prog, $expected, $results, $::TODO ) unless $ok;
196 { rmtree $_ if -d $_ }
202 my $expected = shift;
204 my @got = sort split "\n", $got ;
205 my @expected = sort split "\n", $expected ;
207 return "@got" eq "@expected";
212 my($switch, $prog, $expected, $results, $todo) = @_;
213 my $err_line = "PROG: $switch\n$prog\n" .
214 "EXPECTED:\n$expected\n" .
217 $err_line =~ s/^/# /mg;
218 print $err_line; # Harness can't filter it out from STDERR.
221 print STDERR $err_line;