Commit | Line | Data |
8ebc5c01 |
1 | #!./perl |
2 | |
3 | BEGIN { |
4 | chdir 't' if -d 't'; |
5 | @INC = '../lib'; |
6 | $ENV{PERL5LIB} = '../lib'; |
e5e1b98b |
7 | require Config; import Config; |
8ebc5c01 |
8 | } |
9 | |
10 | $| = 1; |
11 | |
e5e1b98b |
12 | my $Is_VMS = $^O eq 'VMS'; |
68dc0745 |
13 | my $Is_MSWin32 = $^O eq 'MSWin32'; |
8ebc5c01 |
14 | my $tmpfile = "tmp0000"; |
15 | my $i = 0 ; |
16 | 1 while -f ++$tmpfile; |
44a8e56a |
17 | END { if ($tmpfile) { 1 while unlink $tmpfile} } |
8ebc5c01 |
18 | |
19 | my @prgs = () ; |
599cee73 |
20 | my @w_files = () ; |
8ebc5c01 |
21 | |
599cee73 |
22 | if (@ARGV) |
b3704311 |
23 | { print "ARGV = [@ARGV]\n" ; @w_files = map { s#^#./pragma/warn/#; $_ } @ARGV } |
599cee73 |
24 | else |
b3704311 |
25 | { @w_files = sort glob("pragma/warn/*") } |
599cee73 |
26 | |
27 | foreach (@w_files) { |
28 | |
29 | next if /\.orig$/ ; |
8ebc5c01 |
30 | |
d8b8f155 |
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 | |
45 | undef $/; |
46 | |
47 | print "1..", scalar @prgs, "\n"; |
48 | |
49 | |
50 | for (@prgs){ |
51 | my $switch = ""; |
52 | my @temps = () ; |
53 | if (s/^\s*-\w+//){ |
54 | $switch = $&; |
44a8e56a |
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 ? |
79 | `MCR $^X $switch $tmpfile` : |
68dc0745 |
80 | $Is_MSWin32 ? |
81 | `.\\perl -I../lib $switch $tmpfile 2>&1` : |
44a8e56a |
82 | `sh -c './perl $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; |
8ebc5c01 |
91 | $expected =~ s/\n+$//; |
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 | } |