Once again syncing after too long an absence
[p5sagit/p5-mst-13.2.git] / t / pragma / warnings.t
CommitLineData
8ebc5c01 1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
22d4bb9c 5 @INC = '../lib';
8ebc5c01 6 $ENV{PERL5LIB} = '../lib';
e5e1b98b 7 require Config; import Config;
22d4bb9c 8 $ENV{PERL_DESTRUCT_LEVEL} = 0 unless $ENV{PERL_DESTRUCT_LEVEL} > 3;
8ebc5c01 9}
10
11$| = 1;
12
e5e1b98b 13my $Is_VMS = $^O eq 'VMS';
68dc0745 14my $Is_MSWin32 = $^O eq 'MSWin32';
8ebc5c01 15my $tmpfile = "tmp0000";
16my $i = 0 ;
171 while -f ++$tmpfile;
44a8e56a 18END { if ($tmpfile) { 1 while unlink $tmpfile} }
8ebc5c01 19
20my @prgs = () ;
599cee73 21my @w_files = () ;
8ebc5c01 22
599cee73 23if (@ARGV)
b3704311 24 { print "ARGV = [@ARGV]\n" ; @w_files = map { s#^#./pragma/warn/#; $_ } @ARGV }
599cee73 25else
b3704311 26 { @w_files = sort glob("pragma/warn/*") }
599cee73 27
0e06870b 28my $files = 0;
29foreach my $file (@w_files) {
599cee73 30
4b19af01 31 next if /(~|\.orig|,v)$/;
d8b8f155 32
0e06870b 33 open F, "<$file" or die "Cannot open $file: $!\n" ;
34 my $line = 0;
8ebc5c01 35 while (<F>) {
0e06870b 36 $line++;
8ebc5c01 37 last if /^__END__/ ;
38 }
39
40 {
41 local $/ = undef;
0e06870b 42 $files++;
43 @prgs = (@prgs, $file, split "\n########\n", <F>) ;
8ebc5c01 44 }
45 close F ;
46}
47
48undef $/;
49
0e06870b 50print "1..", scalar(@prgs)-$files, "\n";
8ebc5c01 51
52
53for (@prgs){
0e06870b 54 unless (/\n/)
55 {
56 print "# From $_\n";
57 next;
58 }
8ebc5c01 59 my $switch = "";
60 my @temps = () ;
61 if (s/^\s*-\w+//){
62 $switch = $&;
3937c24e 63 $switch =~ s/(-\S*[A-Z]\S*)/"$1"/ if $Is_VMS; # protect uc switches
8ebc5c01 64 }
65 my($prog,$expected) = split(/\nEXPECT\n/, $_);
66 if ( $prog =~ /--FILE--/) {
67 my(@files) = split(/\n--FILE--\s*([^\s\n]*)\s*\n/, $prog) ;
68 shift @files ;
69 die "Internal error test $i didn't split into pairs, got " .
70 scalar(@files) . "[" . join("%%%%", @files) ."]\n"
71 if @files % 2 ;
72 while (@files > 2) {
73 my $filename = shift @files ;
74 my $code = shift @files ;
75 push @temps, $filename ;
76 open F, ">$filename" or die "Cannot open $filename: $!\n" ;
77 print F $code ;
78 close F ;
79 }
80 shift @files ;
81 $prog = shift @files ;
82 }
44a8e56a 83 open TEST, ">$tmpfile";
84 print TEST $prog,"\n";
8ebc5c01 85 close TEST;
44a8e56a 86 my $results = $Is_VMS ?
8e8b254b 87 `./perl "-I../lib" $switch $tmpfile 2>&1` :
68dc0745 88 $Is_MSWin32 ?
89 `.\\perl -I../lib $switch $tmpfile 2>&1` :
0453d815 90 `./perl -I../lib $switch $tmpfile 2>&1`;
8ebc5c01 91 my $status = $?;
8ebc5c01 92 $results =~ s/\n+$//;
44a8e56a 93 # allow expected output to be written as if $prog is on STDIN
94 $results =~ s/tmp\d+/-/g;
95 $results =~ s/\n%[A-Z]+-[SIWEF]-.*$// if $Is_VMS; # clip off DCL status msg
f0ec1f9a 96# bison says 'parse error' instead of 'syntax error',
2c88fa88 97# various yaccs may or may not capitalize 'syntax'.
2a8ee232 98 $results =~ s/^(syntax|parse) error/syntax error/mig;
d33b2eba 99 # allow all tests to run when there are leaks
100 $results =~ s/Scalars leaked: \d+\n//g;
8ebc5c01 101 $expected =~ s/\n+$//;
3b558104 102 my $prefix = ($results =~ s#^PREFIX(\n|$)##) ;
e5e1b98b 103 # any special options? (OPTIONS foo bar zap)
104 my $option_regex = 0;
105 if ($expected =~ s/^OPTIONS? (.+)\n//) {
106 foreach my $option (split(' ', $1)) {
107 if ($option eq 'regex') { # allow regular expressions
108 $option_regex = 1;
109 } else {
110 die "$0: Unknown OPTION '$option'\n";
111 }
112 }
113 }
8ebc5c01 114 if ( $results =~ s/^SKIPPED\n//) {
115 print "$results\n" ;
116 }
e5e1b98b 117 elsif (($prefix && (( $option_regex && $results !~ /^$expected/) ||
118 (!$option_regex && $results !~ /^\Q$expected/))) or
119 (!$prefix && (( $option_regex && $results !~ /^$expected/) ||
120 (!$option_regex && $results ne $expected)))) {
8ebc5c01 121 print STDERR "PROG: $switch\n$prog\n";
122 print STDERR "EXPECTED:\n$expected\n";
123 print STDERR "GOT:\n$results\n";
124 print "not ";
125 }
126 print "ok ", ++$i, "\n";
127 foreach (@temps)
128 { unlink $_ if $_ }
129}