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