8 $VERSION = $VERSION = "1.02";
11 @EXPORT= qw(&runtests);
12 @EXPORT_OK= qw($verbose $switches);
15 $Test::Harness::verbose = 0;
16 $Test::Harness::switches = "-w";
21 my($test,$te,$ok,$next,$max,$totmax, $files,$pct,@failed);
25 local($ENV{'PERL5LIB'}) = join($Config{path_sep}, @INC); # pass -I flags to children
27 my $t_start = new Benchmark;
28 while ($test = shift(@tests)) {
31 print "$te" . '.' x (20 - length($te));
33 open($fh,"$^X $Test::Harness::switches $test|") || (print "can't run. $!\n");
34 $ok = $next = $max = 0;
37 if( $Test::Harness::verbose ){
41 if (/^1\.\.([0-9]+)/) {
47 if (/^not ok ([0-9]*)/){
49 } elsif (/^ok (.*)/ && $1 == $next) {
56 close($fh); # must close to reap child resource values
58 my $estatus = $wstatus >> 8;
60 if ($ok == $max && $next == $max && ! $wstatus) {
65 print canonfailed($max,@failed);
68 print "FAILED before any test output arrived\n";
70 print canonfailed($max,$next+1..$max);
74 print "\tTest returned status $estatus (wstat $wstatus)\n";
80 my $t_total = timediff(new Benchmark, $t_start);
84 print "All tests successful.\n";
86 die "FAILED--no tests were run for some reason.\n";
89 $pct = sprintf("%.2f", $good / $total * 100);
91 die "Failed 1 test script, $pct% okay.\n";
93 die "Failed $bad/$total test scripts, $pct% okay.\n";
96 printf("Files=%d, Tests=%d, %s\n", $files, $totmax, timestr($t_total, 'nop'));
99 sub canonfailed ($@) {
100 my($max,@failed) = @_;
101 my $failed = @failed;
105 my $last = $min = shift @failed;
107 for (@failed, $failed[-1]) { # don't forget the last one
108 if ($_ > $last+1 || $_ == $last) {
112 push @canon, "$min-$last";
119 push @result, "FAILED tests @canon\n";
121 push @result, "FAILED test $last\n";
124 push @result, "\tFailed $failed/$max tests, ";
125 push @result, sprintf("%.2f",100*(1-$failed/$max)), "% okay\n";
134 Test::Harness - run perl standard test scripts with statistics
144 Perl test scripts print to standard output C<"ok N"> for each single
145 test, where C<N> is an increasing sequence of integers. The first line
146 output by a standard test scxript is C<"1..M"> with C<M> being the
147 number of tests that should be run within the test
148 script. Test::Harness::runscripts(@tests) runs all the testscripts
149 named as arguments and checks standard output for the expected
152 After all tests have been performed, runscripts() prints some
153 performance statistics that are computed by the Benchmark module.
157 C<&runscripts> is exported by Test::Harness per default.
163 =item C<All tests successful.\nFiles=%d, Tests=%d, %s>
165 If all tests are successful some statistics about the performance are
168 =item C<Failed 1 test, $pct% okay.>
170 =item C<Failed %d/%d tests, %.2f%% okay.>
172 If not all tests were successful, the script dies with one of the
179 See L<Benchmark> for the underlying timing routines.
183 Either Tim Bunce or Andreas Koenig, we don't know. What we know for
184 sure is, that it was inspired by Larry Wall's TEST script that came
185 with perl distributions for ages. Current maintainer is Andreas
190 Test::Harness uses $^X to determine the perl binary to run the tests
191 with. Test scripts running via the shebang (C<#!>) line may not be portable
192 because $^X is not consistent for shebang scripts across
193 platforms. This is no problem when Test::Harness is run with an
194 absolute path to the perl binary.