integrate cfgperl contents into mainline
[p5sagit/p5-mst-13.2.git] / lib / Test / Harness.pm
index 8804cbd..9902741 100644 (file)
@@ -1,14 +1,14 @@
 package Test::Harness;
 
-BEGIN {require 5.002;}
+use 5.005_64;
 use Exporter;
 use Benchmark;
 use Config;
 use FileHandle;
 use strict;
 
-use vars qw($VERSION $verbose $switches $have_devel_corestack $curtest
-           @ISA @EXPORT @EXPORT_OK);
+our($VERSION, $verbose, $switches, $have_devel_corestack, $curtest,
+    @ISA, @EXPORT, @EXPORT_OK);
 $have_devel_corestack = 0;
 
 $VERSION = "1.1604";
@@ -64,30 +64,46 @@ sub runtests {
 
     # pass -I flags to children
     my $old5lib = $ENV{PERL5LIB};
-    local($ENV{'PERL5LIB'}) = join($Config{path_sep}, @INC);
 
-    if ($^O eq 'VMS') { $switches =~ s/-(\S*[A-Z]\S*)/"-$1"/g }
+    # VMS has a 255-byte limit on the length of %ENV entries, so
+    # toss the ones that involve perl_root, the install location
+    # for VMS
+    my $new5lib;
+    if ($^O eq 'VMS') {
+       $new5lib = join($Config{path_sep}, grep {!/perl_root/i;} @INC);
+       $switches =~ s/-(\S*[A-Z]\S*)/"-$1"/g;
+    }
+    else {
+        $new5lib = join($Config{path_sep}, @INC);
+    }
+
+    local($ENV{'PERL5LIB'}) = $new5lib;
 
     my @dir_files = globdir $files_in_dir if defined $files_in_dir;
     my $t_start = new Benchmark;
     while ($test = shift(@tests)) {
        $te = $test;
        chop($te);
-       if ($^O eq 'VMS') { $te =~ s/^.*\.t\./[.t./; }
+       if ($^O eq 'VMS') { $te =~ s/^.*\.t\./[.t./s; }
        my $blank = (' ' x 77);
        my $leader = "$te" . '.' x (20 - length($te));
        my $ml = "";
-       $ml = "\r$blank\r$leader" if -t STDOUT and not $ENV{HARNESS_NOTTY};
+       $ml = "\r$blank\r$leader"
+           if -t STDOUT and not $ENV{HARNESS_NOTTY} and not $verbose;
        print $leader;
        my $fh = new FileHandle;
        $fh->open($test) or print "can't open $test. $!\n";
        my $first = <$fh>;
        my $s = $switches;
-       $s .= q[ "-T"] if $first =~ /^#!.*\bperl.*-\w*T/;
+       $s .= " $ENV{'HARNESS_PERL_SWITCHES'}"
+           if exists $ENV{'HARNESS_PERL_SWITCHES'};
+       $s .= join " ", q[ "-T"], map {qq["-I$_"]} @INC
+           if $first =~ /^#!.*\bperl.*-\w*T/;
        $fh->close or print "can't close $test. $!\n";
-       my $cmd = ($ENV{'COMPILE_TEST'})? 
-"./perl -I../lib ../utils/perlcc $test -run 2>> ./compilelog |" 
-                                                                                                                       :  "$^X $s $test|";
+       my $cmd = ($ENV{'HARNESS_COMPILE_TEST'})
+               ? "./perl -I../lib ../utils/perlcc $test "
+                 . "-run 2>> ./compilelog |" 
+               : "$^X $s $test|";
        $cmd = "MCR $cmd" if $^O eq 'VMS';
        $fh->open($cmd) or print "can't run $test. $!\n";
        $ok = $next = $max = 0;
@@ -116,7 +132,7 @@ sub runtests {
                my $this = $next;
                if (/^not ok\s*(\d*)/){
                    $this = $1 if $1 > 0;
-                   print "${ml}NOK $this\n" if $ml;
+                   print "${ml}NOK $this" if $ml;
                    if (!$todo{$this}) {
                        push @failed, $this;
                    } else {
@@ -299,7 +315,7 @@ sub runtests {
            die "Failed $bad/$total test scripts, $pct% okay.$subpct\n";
        }
     }
-    printf("Files=%d,  Tests=%d, %s\n", $files, $totmax, timestr($t_total, 'nop'));
+    printf("Files=%d, Tests=%d, %s\n", $files, $totmax, timestr($t_total, 'nop'));
 
     return ($bad == 0 && $totmax) ;
 }
@@ -482,6 +498,9 @@ harness to output more frequent progress messages using carriage returns.
 Some consoles may not handle carriage returns properly (which results
 in a somewhat messy output).
 
+Setting C<HARNESS_COMPILE_TEST> to a true value will make harness attempt
+to compile the test using C<perlcc> before running it.
+
 If C<HARNESS_FILELEAK_IN_DIR> is set to the name of a directory, harness
 will check after each test whether new files appeared in that directory,
 and report them as
@@ -492,6 +511,11 @@ If relative, directory name is with respect to the current directory at
 the moment runtests() was called.  Putting absolute path into 
 C<HARNESS_FILELEAK_IN_DIR> may give more predicatable results.
 
+The value of C<HARNESS_PERL_SWITCHES> will be prepended to the
+switches used to invoke perl on each test.  For example, setting
+C<HARNESS_PERL_SWITCHES> to "-W" will run all tests with all
+warnings enabled.
+
 Harness sets C<HARNESS_ACTIVE> before executing the individual tests.
 This allows the tests to determine if they are being executed through the
 harness or by any other means.