1N/A#!./perl
1N/A
1N/ABEGIN {
1N/A chdir 't' if -d 't';
1N/A @INC = '../lib';
1N/A $ENV{PERL5LIB} = '../lib';
1N/A require Config; import Config;
1N/A}
1N/A
1N/Ause File::Path;
1N/Ause File::Spec::Functions;
1N/A
1N/A$| = 1;
1N/A
1N/Amy $Is_VMS = $^O eq 'VMS';
1N/Amy $Is_MSWin32 = $^O eq 'MSWin32';
1N/Amy $Is_NetWare = $^O eq 'NetWare';
1N/Amy $Is_MacOS = $^O eq 'MacOS';
1N/Amy $tmpfile = "tmp0000";
1N/Amy $i = 0 ;
1N/A1 while -e ++$tmpfile;
1N/AEND { if ($tmpfile) { 1 while unlink $tmpfile} }
1N/A
1N/Amy @prgs = () ;
1N/Amy @w_files = () ;
1N/A
1N/Aif (@ARGV)
1N/A { print "ARGV = [@ARGV]\n" ;
1N/A if ($^O eq 'MacOS') {
1N/A @w_files = map { s#^#:lib:warnings:#; $_ } @ARGV
1N/A } else {
1N/A @w_files = map { s#^#./lib/warnings/#; $_ } @ARGV
1N/A }
1N/A }
1N/Aelse
1N/A { @w_files = sort glob(catfile(curdir(), "lib", "warnings", "*")) }
1N/A
1N/Amy $files = 0;
1N/Aforeach my $file (@w_files) {
1N/A
1N/A next if $file =~ /(~|\.orig|,v)$/;
1N/A next if $file =~ /perlio$/ && !(find PerlIO::Layer 'perlio');
1N/A next if -d $file;
1N/A
1N/A open F, "<$file" or die "Cannot open $file: $!\n" ;
1N/A my $line = 0;
1N/A while (<F>) {
1N/A $line++;
1N/A last if /^__END__/ ;
1N/A }
1N/A
1N/A {
1N/A local $/ = undef;
1N/A $files++;
1N/A @prgs = (@prgs, $file, split "\n########\n", <F>) ;
1N/A }
1N/A close F ;
1N/A}
1N/A
1N/Aundef $/;
1N/A
1N/Aprint "1.." . (scalar(@prgs)-$files) . "\n";
1N/A
1N/A
1N/Afor (@prgs){
1N/A unless (/\n/)
1N/A {
1N/A print "# From $_\n";
1N/A next;
1N/A }
1N/A my $switch = "";
1N/A my @temps = () ;
1N/A my @temp_path = () ;
1N/A if (s/^\s*-\w+//){
1N/A $switch = $&;
1N/A $switch =~ s/(-\S*[A-Z]\S*)/"$1"/ if $Is_VMS; # protect uc switches
1N/A }
1N/A my($prog,$expected) = split(/\nEXPECT\n/, $_);
1N/A if ( $prog =~ /--FILE--/) {
1N/A my(@files) = split(/\n--FILE--\s*([^\s\n]*)\s*\n/, $prog) ;
1N/A shift @files ;
1N/A die "Internal error test $i didn't split into pairs, got " .
1N/A scalar(@files) . "[" . join("%%%%", @files) ."]\n"
1N/A if @files % 2 ;
1N/A while (@files > 2) {
1N/A my $filename = shift @files ;
1N/A my $code = shift @files ;
1N/A push @temps, $filename ;
1N/A if ($filename =~ m#(.*)/#) {
1N/A mkpath($1);
1N/A push(@temp_path, $1);
1N/A }
1N/A open F, ">$filename" or die "Cannot open $filename: $!\n" ;
1N/A print F $code ;
1N/A close F or die "Cannot close $filename: $!\n";
1N/A }
1N/A shift @files ;
1N/A $prog = shift @files ;
1N/A }
1N/A
1N/A # fix up some paths
1N/A if ($^O eq 'MacOS') {
1N/A $prog =~ s|require "./abc(d)?";|require ":abc$1";|g;
1N/A $prog =~ s|"\."|":"|g;
1N/A }
1N/A
1N/A open TEST, ">$tmpfile" or die "Cannot open >$tmpfile: $!";
1N/A print TEST q{
1N/A BEGIN {
1N/A open(STDERR, ">&STDOUT")
1N/A or die "Can't dup STDOUT->STDERR: $!;";
1N/A }
1N/A };
1N/A print TEST "\n#line 1\n"; # So the line numbers don't get messed up.
1N/A print TEST $prog,"\n";
1N/A close TEST or die "Cannot close $tmpfile: $!";
1N/A my $results = $Is_VMS ?
1N/A `./perl "-I../lib" $switch $tmpfile` :
1N/A $Is_MSWin32 ?
1N/A `.\\perl -I../lib $switch $tmpfile` :
1N/A $Is_NetWare ?
1N/A `perl -I../lib $switch $tmpfile` :
1N/A $Is_MacOS ?
1N/A `$^X -I::lib $switch -MMac::err=unix $tmpfile` :
1N/A `./perl -I../lib $switch $tmpfile`;
1N/A my $status = $?;
1N/A $results =~ s/\n+$//;
1N/A # allow expected output to be written as if $prog is on STDIN
1N/A $results =~ s/tmp\d+/-/g;
1N/A if ($^O eq 'VMS') {
1N/A # some tests will trigger VMS messages that won't be expected
1N/A $results =~ s/\n?%[A-Z]+-[SIWEF]-[A-Z]+,.*//;
1N/A
1N/A # pipes double these sometimes
1N/A $results =~ s/\n\n/\n/g;
1N/A }
1N/A# bison says 'parse error' instead of 'syntax error',
1N/A# various yaccs may or may not capitalize 'syntax'.
1N/A $results =~ s/^(syntax|parse) error/syntax error/mig;
1N/A # allow all tests to run when there are leaks
1N/A $results =~ s/Scalars leaked: \d+\n//g;
1N/A
1N/A # fix up some paths
1N/A if ($^O eq 'MacOS') {
1N/A $results =~ s|:abc\.pm\b|abc.pm|g;
1N/A $results =~ s|:abc(d)?\b|./abc$1|g;
1N/A }
1N/A
1N/A $expected =~ s/\n+$//;
1N/A my $prefix = ($results =~ s#^PREFIX(\n|$)##) ;
1N/A # any special options? (OPTIONS foo bar zap)
1N/A my $option_regex = 0;
1N/A my $option_random = 0;
1N/A if ($expected =~ s/^OPTIONS? (.+)\n//) {
1N/A foreach my $option (split(' ', $1)) {
1N/A if ($option eq 'regex') { # allow regular expressions
1N/A $option_regex = 1;
1N/A }
1N/A elsif ($option eq 'random') { # all lines match, but in any order
1N/A $option_random = 1;
1N/A }
1N/A else {
1N/A die "$0: Unknown OPTION '$option'\n";
1N/A }
1N/A }
1N/A }
1N/A die "$0: can't have OPTION regex and random\n"
1N/A if $option_regex + option_random > 1;
1N/A if ( $results =~ s/^SKIPPED\n//) {
1N/A print "$results\n" ;
1N/A }
1N/A elsif ($option_random)
1N/A {
1N/A print "not " if !randomMatch($results, $expected);
1N/A }
1N/A elsif (($prefix && (( $option_regex && $results !~ /^$expected/) ||
1N/A (!$option_regex && $results !~ /^\Q$expected/))) or
1N/A (!$prefix && (( $option_regex && $results !~ /^$expected/) ||
1N/A (!$option_regex && $results ne $expected)))) {
1N/A print STDERR "PROG: $switch\n$prog\n";
1N/A print STDERR "EXPECTED:\n$expected\n";
1N/A print STDERR "GOT:\n$results\n";
1N/A print "not ";
1N/A }
1N/A print "ok " . ++$i . "\n";
1N/A foreach (@temps)
1N/A { unlink $_ if $_ }
1N/A foreach (@temp_path)
1N/A { rmtree $_ if -d $_ }
1N/A}
1N/A
1N/Asub randomMatch
1N/A{
1N/A my $got = shift ;
1N/A my $expected = shift;
1N/A
1N/A my @got = sort split "\n", $got ;
1N/A my @expected = sort split "\n", $expected ;
1N/A
1N/A return "@got" eq "@expected";
1N/A
1N/A}