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\s*(.*)\n//m and $todo_reason = $1;
77 # If the TODO reason starts ? then it's taken as a code snippet to evaluate
78 # This provides the flexibility to have conditional TODOs
79 if ($todo_reason =~ s/^\?//) {
80 my $temp = eval $todo_reason;
82 die "# In TODO code reason:\n# $todo_reason\n$@";
86 if ( $prog =~ /--FILE--/) {
87 my(@files) = split(/\n--FILE--\s*([^\s\n]*)\s*\n/, $prog) ;
89 die "Internal error: test $_ didn't split into pairs, got " .
90 scalar(@files) . "[" . join("%%%%", @files) ."]\n"
93 my $filename = shift @files ;
94 my $code = shift @files ;
95 push @temps, $filename ;
96 if ($filename =~ m#(.*)/#) {
100 open F, ">$filename" or die "Cannot open $filename: $!\n" ;
102 close F or die "Cannot close $filename: $!\n";
105 $prog = shift @files ;
110 $prog =~ s|require "./abc(d)?";|require ":abc$1";|g;
111 $prog =~ s|"\."|":"|g;
114 open TEST, ">$tmpfile" or die "Cannot open >$tmpfile: $!";
117 open(STDERR, ">&STDOUT")
118 or die "Can't dup STDOUT->STDERR: $!;";
121 print TEST "\n#line 1\n"; # So the line numbers don't get messed up.
122 print TEST $prog,"\n";
123 close TEST or die "Cannot close $tmpfile: $!";
124 my $results = runperl( switches => [$switch], stderr => 1, progfile => $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;
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;
169 if ($results =~ s/^SKIPPED\n//) {
173 elsif ($option_random) {
174 $ok = randomMatch($results, $expected);
176 elsif ($option_regex) {
177 $ok = $results =~ /^$expected/;
180 $ok = $results =~ /^\Q$expected/;
183 $ok = $results eq $expected;
186 print_err_line( $switch, $prog, $expected, $results, $todo ) unless $ok;
188 our $TODO = $todo ? $todo_reason : 0;
194 { rmtree $_ if -d $_ }
200 my $expected = shift;
202 my @got = sort split "\n", $got ;
203 my @expected = sort split "\n", $expected ;
205 return "@got" eq "@expected";
210 my($switch, $prog, $expected, $results, $todo) = @_;
211 my $err_line = "PROG: $switch\n$prog\n" .
212 "EXPECTED:\n$expected\n" .
215 $err_line =~ s/^/# /mg;
216 print $err_line; # Harness can't filter it out from STDERR.
219 print STDERR $err_line;