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