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