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