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