Commit | Line | Data |
f126f811 |
1 | #!./perl |
bd4dea8e |
2 | |
3 | BEGIN { |
4 | chdir 't' if -d 't'; |
5 | @INC = '../lib'; |
6 | $ENV{PERL5LIB} = '../lib'; |
7 | require Config; import Config; |
8 | } |
9 | |
99ef548b |
10 | use File::Path; |
e69a2255 |
11 | use File::Spec::Functions; |
99ef548b |
12 | |
bd4dea8e |
13 | $| = 1; |
14 | |
15 | my $Is_VMS = $^O eq 'VMS'; |
16 | my $Is_MSWin32 = $^O eq 'MSWin32'; |
17 | my $Is_NetWare = $^O eq 'NetWare'; |
e69a2255 |
18 | my $Is_MacOS = $^O eq 'MacOS'; |
bd4dea8e |
19 | my $tmpfile = "tmp0000"; |
20 | my $i = 0 ; |
e69a2255 |
21 | 1 while -e ++$tmpfile; |
bd4dea8e |
22 | END { if ($tmpfile) { 1 while unlink $tmpfile} } |
23 | |
24 | my @prgs = () ; |
25 | my @w_files = () ; |
26 | |
27 | if (@ARGV) |
e69a2255 |
28 | { print "ARGV = [@ARGV]\n" ; |
29 | if ($^O eq 'MacOS') { |
30 | @w_files = map { s#^#:lib:warnings:#; $_ } @ARGV |
31 | } else { |
32 | @w_files = map { s#^#./lib/warnings/#; $_ } @ARGV |
33 | } |
34 | } |
bd4dea8e |
35 | else |
e69a2255 |
36 | { @w_files = sort glob(catfile(curdir(), "lib", "warnings", "*")) } |
bd4dea8e |
37 | |
38 | my $files = 0; |
39 | foreach my $file (@w_files) { |
40 | |
41 | next if $file =~ /(~|\.orig|,v)$/; |
6b5da1a3 |
42 | next if $file =~ /perlio$/ && !(find PerlIO::Layer 'perlio'); |
bd4dea8e |
43 | |
44 | open F, "<$file" or die "Cannot open $file: $!\n" ; |
45 | my $line = 0; |
46 | while (<F>) { |
f126f811 |
47 | $line++; |
bd4dea8e |
48 | last if /^__END__/ ; |
49 | } |
50 | |
51 | { |
52 | local $/ = undef; |
f126f811 |
53 | $files++; |
bd4dea8e |
54 | @prgs = (@prgs, $file, split "\n########\n", <F>) ; |
55 | } |
56 | close F ; |
57 | } |
58 | |
59 | undef $/; |
60 | |
61 | print "1..", scalar(@prgs)-$files, "\n"; |
f126f811 |
62 | |
63 | |
bd4dea8e |
64 | for (@prgs){ |
65 | unless (/\n/) |
66 | { |
f126f811 |
67 | print "# From $_\n"; |
68 | next; |
bd4dea8e |
69 | } |
70 | my $switch = ""; |
71 | my @temps = () ; |
99ef548b |
72 | my @temp_path = () ; |
bd4dea8e |
73 | if (s/^\s*-\w+//){ |
74 | $switch = $&; |
75 | $switch =~ s/(-\S*[A-Z]\S*)/"$1"/ if $Is_VMS; # protect uc switches |
76 | } |
77 | my($prog,$expected) = split(/\nEXPECT\n/, $_); |
78 | if ( $prog =~ /--FILE--/) { |
79 | my(@files) = split(/\n--FILE--\s*([^\s\n]*)\s*\n/, $prog) ; |
80 | shift @files ; |
f126f811 |
81 | die "Internal error test $i didn't split into pairs, got " . |
bd4dea8e |
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 |
88 | if ($filename =~ m#(.*)/#) { |
89 | mkpath($1); |
90 | push(@temp_path, $1); |
91 | } |
bd4dea8e |
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 |
95 | } |
96 | shift @files ; |
97 | $prog = shift @files ; |
98 | } |
e69a2255 |
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 |
108 | BEGIN { |
109 | open(STDERR, ">&STDOUT") |
d6920b13 |
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: $!"; |
bd4dea8e |
116 | my $results = $Is_VMS ? |
be708cc0 |
117 | `./perl "-I../lib" $switch $tmpfile` : |
bd4dea8e |
118 | $Is_MSWin32 ? |
be708cc0 |
119 | `.\\perl -I../lib $switch $tmpfile` : |
bd4dea8e |
120 | $Is_NetWare ? |
be708cc0 |
121 | `perl -I../lib $switch $tmpfile` : |
122 | $Is_MacOS ? |
123 | `$^X -I::lib $switch -MMac::err=unix $tmpfile` : |
d6920b13 |
124 | `./perl -I../lib $switch $tmpfile`; |
bd4dea8e |
125 | my $status = $?; |
126 | $results =~ s/\n+$//; |
127 | # allow expected output to be written as if $prog is on STDIN |
128 | $results =~ s/tmp\d+/-/g; |
765ebaf2 |
129 | if ($^O eq 'VMS') { |
130 | # some tests will trigger VMS messages that won't be expected |
131 | $results =~ s/\n?%[A-Z]+-[SIWEF]-[A-Z]+,.*//; |
132 | |
133 | # pipes double these sometimes |
134 | $results =~ s/\n\n/\n/g; |
135 | } |
bd4dea8e |
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; |
e69a2255 |
141 | |
142 | # fix up some paths |
143 | if ($^O eq 'MacOS') { |
144 | $results =~ s|:abc\.pm\b|abc.pm|g; |
145 | $results =~ s|:abc(d)?\b|./abc$1|g; |
146 | } |
147 | |
bd4dea8e |
148 | $expected =~ s/\n+$//; |
149 | my $prefix = ($results =~ s#^PREFIX(\n|$)##) ; |
150 | # any special options? (OPTIONS foo bar zap) |
151 | my $option_regex = 0; |
247c8d76 |
152 | my $option_random = 0; |
bd4dea8e |
153 | if ($expected =~ s/^OPTIONS? (.+)\n//) { |
154 | foreach my $option (split(' ', $1)) { |
155 | if ($option eq 'regex') { # allow regular expressions |
156 | $option_regex = 1; |
6b5da1a3 |
157 | } |
247c8d76 |
158 | elsif ($option eq 'random') { # all lines match, but in any order |
159 | $option_random = 1; |
160 | } |
161 | else { |
bd4dea8e |
162 | die "$0: Unknown OPTION '$option'\n"; |
163 | } |
164 | } |
165 | } |
247c8d76 |
166 | die "$0: can't have OPTION regex and random\n" |
167 | if $option_regex + option_random > 1; |
bd4dea8e |
168 | if ( $results =~ s/^SKIPPED\n//) { |
169 | print "$results\n" ; |
170 | } |
247c8d76 |
171 | elsif ($option_random) |
172 | { |
173 | print "not " if !randomMatch($results, $expected); |
174 | } |
bd4dea8e |
175 | elsif (($prefix && (( $option_regex && $results !~ /^$expected/) || |
176 | (!$option_regex && $results !~ /^\Q$expected/))) or |
177 | (!$prefix && (( $option_regex && $results !~ /^$expected/) || |
178 | (!$option_regex && $results ne $expected)))) { |
179 | print STDERR "PROG: $switch\n$prog\n"; |
180 | print STDERR "EXPECTED:\n$expected\n"; |
181 | print STDERR "GOT:\n$results\n"; |
182 | print "not "; |
183 | } |
184 | print "ok ", ++$i, "\n"; |
f126f811 |
185 | foreach (@temps) |
186 | { unlink $_ if $_ } |
99ef548b |
187 | foreach (@temp_path) |
188 | { rmtree $_ if -d $_ } |
bd4dea8e |
189 | } |
247c8d76 |
190 | |
191 | sub randomMatch |
192 | { |
193 | my $got = shift ; |
194 | my $expected = shift; |
195 | |
196 | my @got = sort split "\n", $got ; |
197 | my @expected = sort split "\n", $expected ; |
198 | |
199 | return "@got" eq "@expected"; |
200 | |
201 | } |