use Config;
use strict;
-use vars '$has_time_hires';
-
-BEGIN {
- eval "use Time::HiRes 'time'";
- $has_time_hires = !$@;
-}
use vars qw(
$VERSION
$verbose $switches $debug
$Curtest
$Columns
+ $Timer
$ML $Last_ML_Print
$Strap
+ $has_time_hires
);
+BEGIN {
+ eval "use Time::HiRes 'time'";
+ $has_time_hires = !$@;
+}
+
=head1 NAME
Test::Harness - Run Perl standard test scripts with statistics
=head1 VERSION
-Version 2.50
+Version 2.52
=cut
-$VERSION = "2.50";
+$VERSION = "2.52";
# Backwards compatibility for exportable variable names.
*verbose = *Verbose;
$Switches = "-w";
$Columns = $ENV{HARNESS_COLUMNS} || $ENV{COLUMNS} || 80;
$Columns--; # Some shells have trouble with a full line of text.
+$Timer = $ENV{HARNESS_TIMER} || 0;
=head1 SYNOPSIS
used to set perl command line options used for running the test
script(s). The default value is C<-w>. It overrides C<HARNESS_SWITCHES>.
+=item C<$Test::Harness::Timer>
+
+If set to true, and C<Time::HiRes> is available, print elapsed seconds
+after each test file.
+
=back
if ( $Test::Harness::Debug ) {
print "# Running: ", $Strap->_command_line($tfile), "\n";
}
- my $test_start_time = time;
+ my $test_start_time = $Timer ? time : 0;
my %results = $Strap->analyze_file($tfile) or
do { warn $Strap->{error}, "\n"; next };
- my $test_end_time = time;
- my $elapsed = $test_end_time - $test_start_time;
- $elapsed = $has_time_hires ? sprintf( " %8.3fs", $elapsed ) : "";
+ my $elapsed;
+ if ( $Timer ) {
+ $elapsed = time - $test_start_time;
+ if ( $has_time_hires ) {
+ $elapsed = sprintf( " %8.3fs", $elapsed );
+ }
+ else {
+ $elapsed = sprintf( " %8ss", $elapsed ? $elapsed : "<1" );
+ }
+ }
+ else {
+ $elapsed = "";
+ }
# state of the current test.
my @failed = grep { !$results{details}[$_-1]{ok} }
}
-# For slow connections, we save lots of bandwidth by printing only once
-# per second.
+# Print updates only once per second.
sub _print_ml_less {
- if ( $Last_ML_Print != time ) {
+ my $now = CORE::time;
+ if ( $Last_ML_Print != $now ) {
_print_ml(@_);
- $Last_ML_Print = time;
+ $Last_ML_Print = $now;
}
}
Revision history for Perl extension Test::Harness
+2.52 Sun Jun 26 23:05:19 CDT 2005
+ No changes
+
+2.51_02
+ [ENHANCEMENTS]
+ * The Test::Harness timer is now off by default. Set HARNESS_TIMER
+ true if you want it. Added --timer flag to prove.
+
+2.50_01
+ [FIXES]
+ * Call CORE::time() to figure out if we should print when we're
+ printing once per second. Otherwise, we're using Time::HiRes'
+ version of it. Thanks, Nicholas Clark.
+
+2.50 Tue Jun 21 14:32:12 CDT 2005
+ [FIXES]
+ * Added some includes in t/strap-analyze.t to make Cygwin happy.
+
2.49_02 Tue Jun 21 09:54:44 CDT 2005
[FIXES]
* Added some includes in t/test_harness.t to make Cygwin happy.
's|shuffle' => \$shuffle,
't' => sub { unshift @switches, "-t" }, # Always want -t up front
'T' => sub { unshift @switches, "-T" }, # Always want -T up front
+ 'timer' => \$Test::Harness::Timer,
'v|verbose' => \$Test::Harness::verbose,
'V|version' => sub { print_version(); exit; },
'ext=s@' => \@ext,
-s, --shuffle Run the tests in a random order.
-T Enable tainting checks
-t Enable tainting warnings
+ --timer Print elapsed time after each test file
-v, --verbose Display standard output of test scripts while running them.
-V, --version Display version info
Runs test programs under perl's -T taint mode.
+=head2 --timer
+
+Print elapsed time after each test file
+
=head2 -v, --verbose
Display standard output of test scripts while running them. Also sets
=head1 COPYRIGHT
-Copyright 2003 by Andy Lester C<< <andy@petdance.com> >>.
+Copyright 2005 by Andy Lester C<< <andy@petdance.com> >>.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.