1 # This code is used by lib/warnings.t and lib/feature.t
4 require Config; import Config;
9 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:$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);
61 my $utf8_ok = exists $ENV{PERL_UNICODE} && $ENV{PERL_UNICODE} =~ m{^$|[Dio]} ? 1 : 0;
75 my($prog,$expected) = split(/\nEXPECT(?:\n|$)/, $_, 2);
80 }{$utf8_ok?$1:$2}gexs;
82 my ($todo, $todo_reason);
83 $todo = $prog =~ s/^#\s*TODO(.*)\n//m and $todo_reason = $1;
84 if ( $prog =~ /--FILE--/) {
85 my(@files) = split(/\n--FILE--\s*([^\s\n]*)\s*\n/, $prog) ;
87 die "Internal error: test $_ didn't split into pairs, got " .
88 scalar(@files) . "[" . join("%%%%", @files) ."]\n"
91 my $filename = shift @files ;
92 my $code = shift @files ;
93 push @temps, $filename ;
94 if ($filename =~ m#(.*)/#) {
98 open F, ">$filename" or die "Cannot open $filename: $!\n" ;
100 close F or die "Cannot close $filename: $!\n";
103 $prog = shift @files ;
107 if ($^O eq 'MacOS') {
108 $prog =~ s|require "./abc(d)?";|require ":abc$1";|g;
109 $prog =~ s|"\."|":"|g;
112 open TEST, ">$tmpfile" or die "Cannot open >$tmpfile: $!";
115 open(STDERR, ">&STDOUT")
116 or die "Can't dup STDOUT->STDERR: $!;";
119 print TEST "\n#line 1\n"; # So the line numbers don't get messed up.
120 print TEST $prog,"\n";
121 close TEST or die "Cannot close $tmpfile: $!";
122 my $results = runperl( switches => [$switch], stderr => 1, progfile => $tmpfile );
124 $results =~ s/\n+$//;
125 # allow expected output to be written as if $prog is on STDIN
126 $results =~ s/tmp\d+/-/g;
128 # some tests will trigger VMS messages that won't be expected
129 $results =~ s/\n?%[A-Z]+-[SIWEF]-[A-Z]+,.*//;
131 # pipes double these sometimes
132 $results =~ s/\n\n/\n/g;
134 # bison says 'parse error' instead of 'syntax error',
135 # various yaccs may or may not capitalize 'syntax'.
136 $results =~ s/^(syntax|parse) error/syntax error/mig;
137 # allow all tests to run when there are leaks
138 $results =~ s/Scalars leaked: \d+\n//g;
141 if ($^O eq 'MacOS') {
142 $results =~ s|:abc\.pm\b|abc.pm|g;
143 $results =~ s|:abc(d)?\b|./abc$1|g;
146 $expected =~ s/\n+$//;
147 my $prefix = ($results =~ s#^PREFIX(\n|$)##) ;
148 # any special options? (OPTIONS foo bar zap)
149 my $option_regex = 0;
150 my $option_random = 0;
151 if ($expected =~ s/^OPTIONS? (.+)\n//) {
152 foreach my $option (split(' ', $1)) {
153 if ($option eq 'regex') { # allow regular expressions
156 elsif ($option eq 'random') { # all lines match, but in any order
160 die "$0: Unknown OPTION '$option'\n";
164 die "$0: can't have OPTION regex and random\n"
165 if $option_regex + $option_random > 1;
167 if ( $results =~ s/^SKIPPED\n//) {
170 elsif ($option_random)
172 $ok = randomMatch($results, $expected);
174 elsif (($prefix && (( $option_regex && $results !~ /^$expected/) ||
175 (!$option_regex && $results !~ /^\Q$expected/))) or
176 (!$prefix && (( $option_regex && $results !~ /^$expected/) ||
177 (!$option_regex && $results ne $expected)))) {
178 my $err_line = "PROG: $switch\n$prog\n" .
179 "EXPECTED:\n$expected\n" .
182 $err_line =~ s/^/# /mg;
183 print $err_line; # Harness can't filter it out from STDERR.
186 print STDERR $err_line;
191 our $TODO = $todo ? $todo_reason : 0;
197 { rmtree $_ if -d $_ }
203 my $expected = shift;
205 my @got = sort split "\n", $got ;
206 my @expected = sort split "\n", $expected ;
208 return "@got" eq "@expected";