lexical warnings; tweaks to places that didn't apply correctly
[p5sagit/p5-mst-13.2.git] / t / pragma / warning.t
1 #!./perl 
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib';
6     $ENV{PERL5LIB} = '../lib';
7 }
8
9 $| = 1;
10
11 my $Is_VMS = $^O eq 'VMS';
12 my $Is_MSWin32 = $^O eq 'MSWin32';
13 my $tmpfile = "tmp0000";
14 my $i = 0 ;
15 1 while -f ++$tmpfile;
16 END {  if ($tmpfile) { 1 while unlink $tmpfile} }
17
18 my @prgs = () ;
19 my @w_files = () ;
20
21 if (@ARGV)
22   { print "ARGV = [@ARGV]\n" ; @w_files = map { s#^#./pragma/warn-#; $_ } @ARGV }
23 else
24   { @w_files = sort glob("pragma/warn-*") }
25
26 foreach (@w_files) {
27
28     next if /\.orig$/ ;
29
30     next if /(~|\.orig)$/;
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                   `MCR $^X $switch $tmpfile` :
79                   $Is_MSWin32 ?
80                   `.\\perl -I../lib $switch $tmpfile 2>&1` :
81                   `sh -c './perl $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     $expected =~ s/\n+$//;
88     my $prefix = ($results =~ s/^PREFIX\n//) ;
89     if ( $results =~ s/^SKIPPED\n//) {
90         print "$results\n" ;
91     }
92     elsif (($prefix and $results !~ /^\Q$expected/) or
93            (!$prefix and $results ne $expected)){
94         print STDERR "PROG: $switch\n$prog\n";
95         print STDERR "EXPECTED:\n$expected\n";
96         print STDERR "GOT:\n$results\n";
97         print "not ";
98     }
99     print "ok ", ++$i, "\n";
100     foreach (@temps) 
101         { unlink $_ if $_ } 
102 }