1N/A#!./perl
1N/A
1N/A# This is written in a peculiar style, since we're trying to avoid
1N/A# most of the constructs we'll be testing for.
1N/A
1N/A$| = 1;
1N/A
1N/A# Let tests know they're running in the perl core. Useful for modules
1N/A# which live dual lives on CPAN.
1N/A$ENV{PERL_CORE} = 1;
1N/A
1N/A# remove empty elements due to insertion of empty symbols via "''p1'" syntax
1N/A@ARGV = grep($_,@ARGV) if $^O eq 'VMS';
1N/A
1N/A# Cheesy version of Getopt::Std. Maybe we should replace it with that.
1N/A@argv = ();
1N/Aif ($#ARGV >= 0) {
1N/A foreach my $idx (0..$#ARGV) {
1N/A push( @argv, $ARGV[$idx] ), next unless $ARGV[$idx] =~ /^-(\S+)$/;
1N/A $core = 1 if $1 eq 'core';
1N/A $verbose = 1 if $1 eq 'v';
1N/A $torture = 1 if $1 eq 'torture';
1N/A $with_utf= 1 if $1 eq 'utf8';
1N/A $bytecompile = 1 if $1 eq 'bytecompile';
1N/A $compile = 1 if $1 eq 'compile';
1N/A $taintwarn = 1 if $1 eq 'taintwarn';
1N/A $ENV{PERL_CORE_MINITEST} = 1 if $1 eq 'minitest';
1N/A if ($1 =~ /^deparse(,.+)?$/) {
1N/A $deparse = 1;
1N/A $deparse_opts = $1;
1N/A }
1N/A }
1N/A}
1N/A@ARGV = @argv;
1N/A
1N/Achdir 't' if -f 't/TEST';
1N/A
1N/Adie "You need to run \"make test\" first to set things up.\n"
1N/A unless -e 'perl' or -e 'perl.exe' or -e 'perl.pm';
1N/A
1N/Aif ($ENV{PERL_3LOG}) { # Tru64 third(1) tool, see perlhack
1N/A unless (-x 'perl.third') {
1N/A unless (-x '../perl.third') {
1N/A die "You need to run \"make perl.third first.\n";
1N/A }
1N/A else {
1N/A print "Symlinking ../perl.third as perl.third...\n";
1N/A die "Failed to symlink: $!\n"
1N/A unless symlink("../perl.third", "perl.third");
1N/A die "Symlinked but no executable perl.third: $!\n"
1N/A unless -x 'perl.third';
1N/A }
1N/A }
1N/A}
1N/A
1N/A# check leakage for embedders
1N/A$ENV{PERL_DESTRUCT_LEVEL} = 2 unless exists $ENV{PERL_DESTRUCT_LEVEL};
1N/A
1N/A$ENV{EMXSHELL} = 'sh'; # For OS/2
1N/A
1N/A# Roll your own File::Find!
1N/Ause TestInit;
1N/Ause File::Spec;
1N/Amy $curdir = File::Spec->curdir;
1N/Amy $updir = File::Spec->updir;
1N/A
1N/Asub _find_tests {
1N/A my($dir) = @_;
1N/A opendir DIR, $dir or die "Trouble opening $dir: $!";
1N/A foreach my $f (sort { $a cmp $b } readdir DIR) {
1N/A next if $f eq $curdir or $f eq $updir or
1N/A $f =~ /^(?:CVS|RCS|SCCS|\.svn)$/;
1N/A
1N/A my $fullpath = File::Spec->catfile($dir, $f);
1N/A
1N/A _find_tests($fullpath) if -d $fullpath;
1N/A $fullpath = VMS::Filespec::unixify($fullpath) if $^O eq 'VMS';
1N/A push @ARGV, $fullpath if $f =~ /\.t$/;
1N/A }
1N/A}
1N/A
1N/Asub _quote_args {
1N/A my ($args) = @_;
1N/A my $argstring = '';
1N/A
1N/A foreach (split(/\s+/,$args)) {
1N/A # In VMS protect with doublequotes because otherwise
1N/A # DCL will lowercase -- unless already doublequoted.
1N/A $_ = q(").$_.q(") if ($^O eq 'VMS') && !/^\"/ && length($_) > 0;
1N/A $argstring .= ' ' . $_;
1N/A }
1N/A return $argstring;
1N/A}
1N/A
1N/Aunless (@ARGV) {
1N/A foreach my $dir (qw(base comp cmd run io op uni)) {
1N/A _find_tests($dir);
1N/A }
1N/A _find_tests("lib") unless $core;
1N/A my $mani = File::Spec->catfile($updir, "MANIFEST");
1N/A if (open(MANI, $mani)) {
1N/A while (<MANI>) { # similar code in t/harness
1N/A if (m!^(ext/\S+/?(?:[^/\s]+\.t|test\.pl)|lib/\S+?(?:\.t|test\.pl))\s!) {
1N/A $t = $1;
1N/A if (!$core || $t =~ m!^lib/[a-z]!)
1N/A {
1N/A $path = File::Spec->catfile($updir, $t);
1N/A push @ARGV, $path;
1N/A $name{$path} = $t;
1N/A }
1N/A }
1N/A }
1N/A close MANI;
1N/A } else {
1N/A warn "$0: cannot open $mani: $!\n";
1N/A }
1N/A unless ($core) {
1N/A _find_tests('pod');
1N/A _find_tests('x2p');
1N/A _find_tests('japh') if $torture;
1N/A }
1N/A}
1N/A
1N/A# Tests known to cause infinite loops for the perlcc tests.
1N/A# %infinite = ( 'comp/require.t', 1, 'op/bop.t', 1, 'lib/hostname.t', 1 );
1N/A%infinite = ();
1N/A
1N/Aif ($deparse) {
1N/A _testprogs('deparse', '', @ARGV);
1N/A}
1N/Aelsif( $compile ) {
1N/A _testprogs('compile', '', @ARGV);
1N/A}
1N/Aelsif( $bytecompile ) {
1N/A _testprogs('bytecompile', '', @ARGV);
1N/A}
1N/Aelse {
1N/A _testprogs('compile', '', @ARGV) if -e "../testcompile";
1N/A _testprogs('perl', '', @ARGV);
1N/A}
1N/A
1N/Asub _testprogs {
1N/A $type = shift @_;
1N/A $args = shift;
1N/A @tests = @_;
1N/A
1N/A print <<'EOT' if ($type eq 'compile');
1N/A------------------------------------------------------------------------------
1N/ATESTING COMPILER
1N/A------------------------------------------------------------------------------
1N/AEOT
1N/A
1N/A print <<'EOT' if ($type eq 'deparse');
1N/A------------------------------------------------------------------------------
1N/ATESTING DEPARSER
1N/A------------------------------------------------------------------------------
1N/AEOT
1N/A
1N/A print <<EOT if ($type eq 'bytecompile');
1N/A------------------------------------------------------------------------------
1N/ATESTING BYTECODE COMPILER
1N/A------------------------------------------------------------------------------
1N/AEOT
1N/A
1N/A $ENV{PERLCC_TIMEOUT} = 120
1N/A if ($type eq 'compile' && !$ENV{PERLCC_TIMEOUT});
1N/A
1N/A $bad = 0;
1N/A $good = 0;
1N/A $total = @tests;
1N/A $files = 0;
1N/A $totmax = 0;
1N/A
1N/A foreach my $t (@tests) {
1N/A unless (exists $name{$t}) {
1N/A my $tname = File::Spec->catfile('t',$t);
1N/A $tname = VMS::Filespec::unixify($tname) if $^O eq 'VMS';
1N/A $name{$t} = $tname;
1N/A }
1N/A }
1N/A my $maxlen = 0;
1N/A foreach (@name{@tests}) {
1N/A s/\.\w+\z/./;
1N/A my $len = length ;
1N/A $maxlen = $len if $len > $maxlen;
1N/A }
1N/A # + 3 : we want three dots between the test name and the "ok"
1N/A $dotdotdot = $maxlen + 3 ;
1N/A my $valgrind = 0;
1N/A my $valgrind_log = 'current.valgrind';
1N/A while ($test = shift @tests) {
1N/A
1N/A if ( $infinite{$test} && $type eq 'compile' ) {
1N/A print STDERR "$test creates infinite loop! Skipping.\n";
1N/A next;
1N/A }
1N/A if ($test =~ /^$/) {
1N/A next;
1N/A }
1N/A if ($type eq 'deparse') {
1N/A if ($test eq "comp/redef.t") {
1N/A # Redefinition happens at compile time
1N/A next;
1N/A }
1N/A elsif ($test =~ m{lib/Switch/t/}) {
1N/A # B::Deparse doesn't support source filtering
1N/A next;
1N/A }
1N/A }
1N/A $te = $name{$test} . '.' x ($dotdotdot - length($name{$test}));
1N/A
1N/A if ($^O ne 'VMS') { # defer printing on VMS due to piping bug
1N/A print $te;
1N/A $te = '';
1N/A }
1N/A
1N/A $test = $OVER{$test} if exists $OVER{$test};
1N/A
1N/A open(SCRIPT,"<$test") or die "Can't run $test.\n";
1N/A $_ = <SCRIPT>;
1N/A close(SCRIPT) unless ($type eq 'deparse');
1N/A if (/#!.*\bperl.*\s-\w*([tT])/) {
1N/A $switch = qq{"-$1"};
1N/A }
1N/A else {
1N/A if ($taintwarn) {
1N/A # not all tests are expected to pass with this option
1N/A $switch = '"-t"';
1N/A }
1N/A else {
1N/A $switch = '';
1N/A }
1N/A }
1N/A
1N/A my $test_executable; # for 'compile' tests
1N/A my $file_opts = "";
1N/A if ($type eq 'deparse') {
1N/A # Look for #line directives which change the filename
1N/A while (<SCRIPT>) {
1N/A $file_opts .= ",-f$3$4"
1N/A if /^#\s*line\s+(\d+)\s+((\w+)|"([^"]+)")/;
1N/A }
1N/A close(SCRIPT);
1N/A }
1N/A
1N/A my $utf = $with_utf ? '-I../lib -Mutf8' : '';
1N/A my $testswitch = '-I. -MTestInit'; # -T will strict . from @INC
1N/A if ($type eq 'deparse') {
1N/A my $deparse =
1N/A "./perl $testswitch $switch -I../lib -MO=-qq,Deparse,-sv1.,".
1N/A "-l$deparse_opts$file_opts ".
1N/A "$test > $test.dp ".
1N/A "&& ./perl $testswitch $switch -I../lib $test.dp |";
1N/A open(RESULTS, $deparse)
1N/A or print "can't deparse '$deparse': $!.\n";
1N/A }
1N/A elsif ($type eq 'bytecompile') {
1N/A my ($pwd, $null);
1N/A if( $^O eq 'MSWin32') {
1N/A $pwd = `cd`;
1N/A $null = 'nul';
1N/A } else {
1N/A $pwd = `pwd`;
1N/A $null = '/dev/null';
1N/A }
1N/A chomp $pwd;
1N/A my $perl = $ENV{PERL} || "$pwd/perl";
1N/A my $bswitch = "-MO=Bytecode,-H,-TI,-s$pwd/$test,";
1N/A $bswitch .= "-TF$test.plc,"
1N/A if $test =~ m(chdir|pod/|CGI/t/carp|lib/DB);
1N/A $bswitch .= "-k,"
1N/A if $test =~ m(deparse|terse|ext/Storable/t/code);
1N/A $bswitch .= "-b,"
1N/A if $test =~ m(op/getpid);
1N/A my $bytecompile =
1N/A "$perl $testswitch $switch -I../lib $bswitch".
1N/A "-o$test.plc $test 2>$null &&".
1N/A "$perl $testswitch $switch -I../lib $utf $test.plc |";
1N/A open(RESULTS,$bytecompile)
1N/A or print "can't byte-compile '$bytecompile': $!.\n";
1N/A }
1N/A elsif ($type eq 'perl') {
1N/A my $perl = $ENV{PERL} || './perl';
1N/A my $redir = $^O eq 'VMS' ? '2>&1' : '';
1N/A if ($ENV{PERL_VALGRIND}) {
1N/A $perl = "valgrind --suppressions=perl.supp --leak-check=yes "
1N/A . "--leak-resolution=high --show-reachable=yes "
1N/A . "--num-callers=50 --logfile-fd=3 $perl";
1N/A $redir = "3>$valgrind_log";
1N/A }
1N/A my $run = "$perl" . _quote_args("$testswitch $switch $utf") . " $test $redir|";
1N/A open(RESULTS,$run) or print "can't run '$run': $!.\n";
1N/A }
1N/A else {
1N/A my $compile;
1N/A my $pl2c = "$testswitch -I../lib ../utils/perlcc --testsuite " .
1N/A # -O9 for good measure, -fcog is broken ATM
1N/A "$switch -Wb=-O9,-fno-cog -L .. " .
1N/A "-I \".. ../lib/CORE\" $args $utf $test -o ";
1N/A
1N/A if( $^O eq 'MSWin32' ) {
1N/A $test_executable = "$test.exe";
1N/A # hopefully unused name...
1N/A open HACK, "> xweghyz.pl";
1N/A print HACK <<EOT;
1N/A#!./perl
1N/A
1N/Aopen HACK, '.\\perl $pl2c $test_executable |';
1N/A# cl.exe prints the name of the .c file on stdout (\%^\$^#)
1N/Awhile(<HACK>) {m/^\\w+\\.[cC]\$/ && next;print}
1N/Aopen HACK, '$test_executable |';
1N/Awhile(<HACK>) {print}
1N/AEOT
1N/A close HACK;
1N/A $compile = 'xweghyz.pl |';
1N/A }
1N/A else {
1N/A $test_executable = "$test.plc";
1N/A $compile = "./perl $pl2c $test_executable && $test_executable |";
1N/A }
1N/A unlink $test_executable if -f $test_executable;
1N/A open(RESULTS, $compile)
1N/A or print "can't compile '$compile': $!.\n";
1N/A }
1N/A
1N/A $ok = 0;
1N/A $next = 0;
1N/A my $seen_leader = 0;
1N/A my $seen_ok = 0;
1N/A while (<RESULTS>) {
1N/A next if /^\s*$/; # skip blank lines
1N/A if ($verbose) {
1N/A print $_;
1N/A }
1N/A unless (/^\#/) {
1N/A if (/^1\.\.([0-9]+)( todo ([\d ]+))?/) {
1N/A $max = $1;
1N/A %todo = map { $_ => 1 } split / /, $3 if $3;
1N/A $totmax += $max;
1N/A $files += 1;
1N/A unless ($seen_ok) {
1N/A $next = 1;
1N/A $ok = 1;
1N/A }
1N/A $seen_leader = 1;
1N/A }
1N/A else {
1N/A if (/^(not )?ok (\d+)[^\#]*(\s*\#.*)?/) {
1N/A unless ($seen_leader) {
1N/A unless ($seen_ok) {
1N/A $next = 1;
1N/A $ok = 1;
1N/A }
1N/A }
1N/A $seen_ok = 1;
1N/A if ($2 == $next) {
1N/A my($not, $num, $extra) = ($1, $2, $3);
1N/A my($istodo) = $extra =~ /^\s*#\s*TODO/ if $extra;
1N/A $istodo = 1 if $todo{$num};
1N/A
1N/A if( $not && !$istodo ) {
1N/A $ok = 0;
1N/A $next = $num;
1N/A last;
1N/A }
1N/A else {
1N/A $next = $next + 1;
1N/A }
1N/A }
1N/A }
1N/A elsif (/^Bail out!\s*(.*)/i) { # magic words
1N/A die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n");
1N/A }
1N/A else {
1N/A $ok = 0;
1N/A }
1N/A }
1N/A }
1N/A }
1N/A close RESULTS;
1N/A if ($ENV{PERL_VALGRIND}) {
1N/A my @valgrind;
1N/A if (-e $valgrind_log) {
1N/A if (open(V, $valgrind_log)) {
1N/A @valgrind = <V>;
1N/A close V;
1N/A } else {
1N/A warn "$0: Failed to open '$valgrind_log': $!\n";
1N/A }
1N/A }
1N/A if (@valgrind) {
1N/A my $leaks = 0;
1N/A my $errors = 0;
1N/A for my $i (0..$#valgrind) {
1N/A local $_ = $valgrind[$i];
1N/A if (/^==\d+== ERROR SUMMARY: (\d+) errors? /) {
1N/A $errors += $1; # there may be multiple error summaries
1N/A } elsif (/^==\d+== LEAK SUMMARY:/) {
1N/A for my $off (1 .. 4) {
1N/A if ($valgrind[$i+$off] =~
1N/A /(?:lost|reachable):\s+\d+ bytes in (\d+) blocks/) {
1N/A $leaks += $1;
1N/A }
1N/A }
1N/A }
1N/A }
1N/A if ($errors or $leaks) {
1N/A if (rename $valgrind_log, "$test.valgrind") {
1N/A $valgrind++;
1N/A } else {
1N/A warn "$0: Failed to create '$test.valgrind': $!\n";
1N/A }
1N/A }
1N/A } else {
1N/A warn "No valgrind output?\n";
1N/A }
1N/A if (-e $valgrind_log) {
1N/A unlink $valgrind_log
1N/A or warn "$0: Failed to unlink '$valgrind_log': $!\n";
1N/A }
1N/A }
1N/A if ($type eq 'deparse') {
1N/A unlink "./$test.dp";
1N/A }
1N/A if ($ENV{PERL_3LOG}) {
1N/A my $tpp = $test;
1N/A $tpp =~ s:^\.\./::;
1N/A $tpp =~ s:/:_:g;
1N/A $tpp =~ s:\.t$:.3log:;
1N/A rename("perl.3log", $tpp) ||
1N/A die "rename: perl3.log to $tpp: $!\n";
1N/A }
1N/A $next = $next - 1;
1N/A # test if the compiler compiled something
1N/A if( $type eq 'compile' && !-e "$test_executable" ) {
1N/A $ok = 0;
1N/A print "Test did not compile\n";
1N/A }
1N/A if ($ok && $next == $max ) {
1N/A if ($max) {
1N/A print "${te}ok\n";
1N/A $good = $good + 1;
1N/A }
1N/A else {
1N/A print "${te}skipping test on this platform\n";
1N/A $files -= 1;
1N/A }
1N/A }
1N/A else {
1N/A $next += 1;
1N/A print "${te}FAILED at test $next\n";
1N/A $bad = $bad + 1;
1N/A $_ = $test;
1N/A if (/^base/) {
1N/A die "Failed a basic test--cannot continue.\n";
1N/A }
1N/A }
1N/A }
1N/A
1N/A if ($bad == 0) {
1N/A if ($ok) {
1N/A print "All tests successful.\n";
1N/A # XXX add mention of 'perlbug -ok' ?
1N/A }
1N/A else {
1N/A die "FAILED--no tests were run for some reason.\n";
1N/A }
1N/A }
1N/A else {
1N/A $pct = $files ? sprintf("%.2f", ($files - $bad) / $files * 100) : "0.00";
1N/A if ($bad == 1) {
1N/A warn "Failed 1 test script out of $files, $pct% okay.\n";
1N/A }
1N/A else {
1N/A warn "Failed $bad test scripts out of $files, $pct% okay.\n";
1N/A }
1N/A warn <<'SHRDLU_1';
1N/A### Since not all tests were successful, you may want to run some of
1N/A### them individually and examine any diagnostic messages they produce.
1N/A### See the INSTALL document's section on "make test".
1N/ASHRDLU_1
1N/A warn <<'SHRDLU_2' if $good / $total > 0.8;
1N/A### You have a good chance to get more information by running
1N/A### ./perl harness
1N/A### in the 't' directory since most (>=80%) of the tests succeeded.
1N/ASHRDLU_2
1N/A if (eval {require Config; import Config; 1}) {
1N/A if ($Config{usedl} && (my $p = $Config{ldlibpthname})) {
1N/A warn <<SHRDLU_3;
1N/A### You may have to set your dynamic library search path,
1N/A### $p, to point to the build directory:
1N/ASHRDLU_3
1N/A if (exists $ENV{$p} && $ENV{$p} ne '') {
1N/A warn <<SHRDLU_4a;
1N/A### setenv $p `pwd`:\$$p; cd t; ./perl harness
1N/A### $p=`pwd`:\$$p; export $p; cd t; ./perl harness
1N/A### export $p=`pwd`:\$$p; cd t; ./perl harness
1N/ASHRDLU_4a
1N/A } else {
1N/A warn <<SHRDLU_4b;
1N/A### setenv $p `pwd`; cd t; ./perl harness
1N/A### $p=`pwd`; export $p; cd t; ./perl harness
1N/A### export $p=`pwd`; cd t; ./perl harness
1N/ASHRDLU_4b
1N/A }
1N/A warn <<SHRDLU_5;
1N/A### for csh-style shells, like tcsh; or for traditional/modern
1N/A### Bourne-style shells, like bash, ksh, and zsh, respectively.
1N/ASHRDLU_5
1N/A }
1N/A }
1N/A }
1N/A ($user,$sys,$cuser,$csys) = times;
1N/A print sprintf("u=%g s=%g cu=%g cs=%g scripts=%d tests=%d\n",
1N/A $user,$sys,$cuser,$csys,$files,$totmax);
1N/A if ($ENV{PERL_VALGRIND}) {
1N/A my $s = $valgrind == 1 ? '' : 's';
1N/A print "$valgrind valgrind report$s created.\n", ;
1N/A }
1N/A}
1N/Aexit ($bad != 0);