This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
consolidated VMS patches (from Craig A. Berry
[perl5.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
PM
26
27foreach (@w_files) {
28
29 next if /\.orig$/ ;
8ebc5c01 30
d8b8f155
CS
31 next if /(~|\.orig)$/;
32
8ebc5c01 33 open F, "<$_" or die "Cannot open $_: $!\n" ;
34 while (<F>) {
35 last if /^__END__/ ;
36 }
37
38 {
39 local $/ = undef;
40 @prgs = (@prgs, split "\n########\n", <F>) ;
41 }
42 close F ;
43}
44
45undef $/;
46
47print "1..", scalar @prgs, "\n";
48
49
50for (@prgs){
51 my $switch = "";
52 my @temps = () ;
53 if (s/^\s*-\w+//){
54 $switch = $&;
3937c24e 55 $switch =~ s/(-\S*[A-Z]\S*)/"$1"/ if $Is_VMS; # protect uc switches
8ebc5c01 56 }
57 my($prog,$expected) = split(/\nEXPECT\n/, $_);
58 if ( $prog =~ /--FILE--/) {
59 my(@files) = split(/\n--FILE--\s*([^\s\n]*)\s*\n/, $prog) ;
60 shift @files ;
61 die "Internal error test $i didn't split into pairs, got " .
62 scalar(@files) . "[" . join("%%%%", @files) ."]\n"
63 if @files % 2 ;
64 while (@files > 2) {
65 my $filename = shift @files ;
66 my $code = shift @files ;
67 push @temps, $filename ;
68 open F, ">$filename" or die "Cannot open $filename: $!\n" ;
69 print F $code ;
70 close F ;
71 }
72 shift @files ;
73 $prog = shift @files ;
74 }
44a8e56a 75 open TEST, ">$tmpfile";
76 print TEST $prog,"\n";
8ebc5c01 77 close TEST;
44a8e56a 78 my $results = $Is_VMS ?
f0963acb 79 `./perl "-I../lib" $switch $tmpfile 2>&1` :
68dc0745 80 $Is_MSWin32 ?
81 `.\\perl -I../lib $switch $tmpfile 2>&1` :
0453d815 82 `./perl -I../lib $switch $tmpfile 2>&1`;
8ebc5c01 83 my $status = $?;
8ebc5c01 84 $results =~ s/\n+$//;
44a8e56a 85 # allow expected output to be written as if $prog is on STDIN
86 $results =~ s/tmp\d+/-/g;
87 $results =~ s/\n%[A-Z]+-[SIWEF]-.*$// if $Is_VMS; # clip off DCL status msg
f0ec1f9a 88# bison says 'parse error' instead of 'syntax error',
2c88fa88 89# various yaccs may or may not capitalize 'syntax'.
2a8ee232 90 $results =~ s/^(syntax|parse) error/syntax error/mig;
d33b2eba
GS
91 # allow all tests to run when there are leaks
92 $results =~ s/Scalars leaked: \d+\n//g;
8ebc5c01 93 $expected =~ s/\n+$//;
f0963acb 94 my $prefix = ($results =~ s#^PREFIX(\n|$)##) ;
e5e1b98b
JH
95 # any special options? (OPTIONS foo bar zap)
96 my $option_regex = 0;
97 if ($expected =~ s/^OPTIONS? (.+)\n//) {
98 foreach my $option (split(' ', $1)) {
99 if ($option eq 'regex') { # allow regular expressions
100 $option_regex = 1;
101 } else {
102 die "$0: Unknown OPTION '$option'\n";
103 }
104 }
105 }
8ebc5c01 106 if ( $results =~ s/^SKIPPED\n//) {
107 print "$results\n" ;
108 }
e5e1b98b
JH
109 elsif (($prefix && (( $option_regex && $results !~ /^$expected/) ||
110 (!$option_regex && $results !~ /^\Q$expected/))) or
111 (!$prefix && (( $option_regex && $results !~ /^$expected/) ||
112 (!$option_regex && $results ne $expected)))) {
8ebc5c01 113 print STDERR "PROG: $switch\n$prog\n";
114 print STDERR "EXPECTED:\n$expected\n";
115 print STDERR "GOT:\n$results\n";
116 print "not ";
117 }
118 print "ok ", ++$i, "\n";
119 foreach (@temps)
120 { unlink $_ if $_ }
121}