Commit | Line | Data |
---|---|---|
f126f811 | 1 | #!./perl |
bd4dea8e JH |
2 | |
3 | BEGIN { | |
4 | chdir 't' if -d 't'; | |
5 | @INC = '../lib'; | |
6 | $ENV{PERL5LIB} = '../lib'; | |
7 | require Config; import Config; | |
92ca9816 | 8 | require './test.pl'; |
bd4dea8e JH |
9 | } |
10 | ||
99ef548b | 11 | use File::Path; |
e69a2255 | 12 | use File::Spec::Functions; |
99ef548b | 13 | |
bd4dea8e JH |
14 | $| = 1; |
15 | ||
e69a2255 | 16 | my $Is_MacOS = $^O eq 'MacOS'; |
bd4dea8e | 17 | my $tmpfile = "tmp0000"; |
e69a2255 | 18 | 1 while -e ++$tmpfile; |
bd4dea8e JH |
19 | END { if ($tmpfile) { 1 while unlink $tmpfile} } |
20 | ||
21 | my @prgs = () ; | |
22 | my @w_files = () ; | |
23 | ||
24 | if (@ARGV) | |
e69a2255 JH |
25 | { print "ARGV = [@ARGV]\n" ; |
26 | if ($^O eq 'MacOS') { | |
27 | @w_files = map { s#^#:lib:warnings:#; $_ } @ARGV | |
28 | } else { | |
29 | @w_files = map { s#^#./lib/warnings/#; $_ } @ARGV | |
30 | } | |
31 | } | |
bd4dea8e | 32 | else |
e69a2255 | 33 | { @w_files = sort glob(catfile(curdir(), "lib", "warnings", "*")) } |
bd4dea8e JH |
34 | |
35 | my $files = 0; | |
36 | foreach my $file (@w_files) { | |
37 | ||
38 | next if $file =~ /(~|\.orig|,v)$/; | |
6b5da1a3 | 39 | next if $file =~ /perlio$/ && !(find PerlIO::Layer 'perlio'); |
cbc25c42 | 40 | next if -d $file; |
bd4dea8e JH |
41 | |
42 | open F, "<$file" or die "Cannot open $file: $!\n" ; | |
43 | my $line = 0; | |
44 | while (<F>) { | |
f126f811 | 45 | $line++; |
bd4dea8e JH |
46 | last if /^__END__/ ; |
47 | } | |
48 | ||
49 | { | |
50 | local $/ = undef; | |
f126f811 | 51 | $files++; |
bd4dea8e JH |
52 | @prgs = (@prgs, $file, split "\n########\n", <F>) ; |
53 | } | |
54 | close F ; | |
55 | } | |
56 | ||
57 | undef $/; | |
58 | ||
92ca9816 CB |
59 | plan tests => (scalar(@prgs)-$files); |
60 | ||
f126f811 A |
61 | |
62 | ||
bd4dea8e JH |
63 | for (@prgs){ |
64 | unless (/\n/) | |
65 | { | |
f126f811 A |
66 | print "# From $_\n"; |
67 | next; | |
bd4dea8e JH |
68 | } |
69 | my $switch = ""; | |
70 | my @temps = () ; | |
99ef548b | 71 | my @temp_path = () ; |
bd4dea8e JH |
72 | if (s/^\s*-\w+//){ |
73 | $switch = $&; | |
bd4dea8e JH |
74 | } |
75 | my($prog,$expected) = split(/\nEXPECT\n/, $_); | |
0b1f5750 A |
76 | my ($todo, $todo_reason); |
77 | $todo = $prog =~ s/^#\s*TODO(.*)\n//m and $todo_reason = $1; | |
bd4dea8e JH |
78 | if ( $prog =~ /--FILE--/) { |
79 | my(@files) = split(/\n--FILE--\s*([^\s\n]*)\s*\n/, $prog) ; | |
80 | shift @files ; | |
92ca9816 | 81 | die "Internal error test $test didn't split into pairs, got " . |
bd4dea8e JH |
82 | scalar(@files) . "[" . join("%%%%", @files) ."]\n" |
83 | if @files % 2 ; | |
84 | while (@files > 2) { | |
85 | my $filename = shift @files ; | |
86 | my $code = shift @files ; | |
87 | push @temps, $filename ; | |
99ef548b PM |
88 | if ($filename =~ m#(.*)/#) { |
89 | mkpath($1); | |
90 | push(@temp_path, $1); | |
91 | } | |
bd4dea8e JH |
92 | open F, ">$filename" or die "Cannot open $filename: $!\n" ; |
93 | print F $code ; | |
f126f811 | 94 | close F or die "Cannot close $filename: $!\n"; |
bd4dea8e JH |
95 | } |
96 | shift @files ; | |
97 | $prog = shift @files ; | |
98 | } | |
e69a2255 JH |
99 | |
100 | # fix up some paths | |
101 | if ($^O eq 'MacOS') { | |
102 | $prog =~ s|require "./abc(d)?";|require ":abc$1";|g; | |
103 | $prog =~ s|"\."|":"|g; | |
104 | } | |
105 | ||
f126f811 | 106 | open TEST, ">$tmpfile" or die "Cannot open >$tmpfile: $!"; |
d6920b13 | 107 | print TEST q{ |
f126f811 A |
108 | BEGIN { |
109 | open(STDERR, ">&STDOUT") | |
d6920b13 MS |
110 | or die "Can't dup STDOUT->STDERR: $!;"; |
111 | } | |
112 | }; | |
113 | print TEST "\n#line 1\n"; # So the line numbers don't get messed up. | |
bd4dea8e | 114 | print TEST $prog,"\n"; |
f126f811 | 115 | close TEST or die "Cannot close $tmpfile: $!"; |
92ca9816 | 116 | my $results = runperl( switches => [$switch], stderr => 1, progfile => $tmpfile ); |
bd4dea8e JH |
117 | my $status = $?; |
118 | $results =~ s/\n+$//; | |
119 | # allow expected output to be written as if $prog is on STDIN | |
120 | $results =~ s/tmp\d+/-/g; | |
765ebaf2 CB |
121 | if ($^O eq 'VMS') { |
122 | # some tests will trigger VMS messages that won't be expected | |
123 | $results =~ s/\n?%[A-Z]+-[SIWEF]-[A-Z]+,.*//; | |
487bb909 CB |
124 | |
125 | # pipes double these sometimes | |
126 | $results =~ s/\n\n/\n/g; | |
765ebaf2 | 127 | } |
bd4dea8e JH |
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; | |
e69a2255 JH |
133 | |
134 | # fix up some paths | |
135 | if ($^O eq 'MacOS') { | |
136 | $results =~ s|:abc\.pm\b|abc.pm|g; | |
137 | $results =~ s|:abc(d)?\b|./abc$1|g; | |
138 | } | |
139 | ||
bd4dea8e JH |
140 | $expected =~ s/\n+$//; |
141 | my $prefix = ($results =~ s#^PREFIX(\n|$)##) ; | |
142 | # any special options? (OPTIONS foo bar zap) | |
143 | my $option_regex = 0; | |
247c8d76 | 144 | my $option_random = 0; |
bd4dea8e JH |
145 | if ($expected =~ s/^OPTIONS? (.+)\n//) { |
146 | foreach my $option (split(' ', $1)) { | |
147 | if ($option eq 'regex') { # allow regular expressions | |
148 | $option_regex = 1; | |
6b5da1a3 | 149 | } |
247c8d76 JH |
150 | elsif ($option eq 'random') { # all lines match, but in any order |
151 | $option_random = 1; | |
152 | } | |
153 | else { | |
bd4dea8e JH |
154 | die "$0: Unknown OPTION '$option'\n"; |
155 | } | |
156 | } | |
157 | } | |
247c8d76 JH |
158 | die "$0: can't have OPTION regex and random\n" |
159 | if $option_regex + option_random > 1; | |
92ca9816 | 160 | my $ok = 1; |
bd4dea8e JH |
161 | if ( $results =~ s/^SKIPPED\n//) { |
162 | print "$results\n" ; | |
163 | } | |
247c8d76 JH |
164 | elsif ($option_random) |
165 | { | |
92ca9816 | 166 | $ok = randomMatch($results, $expected); |
247c8d76 | 167 | } |
bd4dea8e JH |
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)))) { | |
0b1f5750 A |
172 | my $err_line = "PROG: $switch\n$prog\n" . |
173 | "EXPECTED:\n$expected\n" . | |
174 | "GOT:\n$results\n"; | |
175 | if ($todo) { | |
176 | $err_line =~ s/^/# /mg; | |
177 | print $err_line; # Harness can't filter it out from STDERR. | |
178 | } | |
179 | else { | |
180 | print STDERR $err_line; | |
181 | } | |
92ca9816 | 182 | $ok = 0; |
bd4dea8e | 183 | } |
92ca9816 CB |
184 | |
185 | $TODO = $todo ? $todo_reason : 0; | |
186 | ok($ok); | |
187 | ||
f126f811 A |
188 | foreach (@temps) |
189 | { unlink $_ if $_ } | |
99ef548b PM |
190 | foreach (@temp_path) |
191 | { rmtree $_ if -d $_ } | |
bd4dea8e | 192 | } |
247c8d76 JH |
193 | |
194 | sub randomMatch | |
195 | { | |
196 | my $got = shift ; | |
197 | my $expected = shift; | |
198 | ||
199 | my @got = sort split "\n", $got ; | |
200 | my @expected = sort split "\n", $expected ; | |
201 | ||
202 | return "@got" eq "@expected"; | |
203 | ||
204 | } |