Subject: | Set HARNESS_IS_VERBOSE when in verbose mode. |
prove sets TEST_VERBOSE for running tests to see when -v is used. MakeMaker will set TEST_VERBOSE. Test::Harness itself sets nothing. Its probably best that TH do it itself rather than the things running TH.
This patch makes Test::Harness set HARNESS_IS_VERBOSE when running in verbose mode. I chose that over TEST_HARNESS because all other TH environment vars use the HARNESS_ prefix and I didn't want to conflate with what MakeMaker already sets.
prove continues to set TEST_VERBOSE for existing tests but it is deprecated.
I've also reorganized the ENVIRONMENT docs to separate environment variables set by TH from those which a user is supposed to set.
Thu Apr 28 19:21:48 PDT 2005 schwern@pobox.com
* Set HARNESS_IS_VERBOSE when running in verbose mode
diff -rN -u old-Test-Harness-2.46/MANIFEST new-Test-Harness-2.46/MANIFEST
--- old-Test-Harness-2.46/MANIFEST 2005-04-28 19:22:21.000000000 -0700
+++ new-Test-Harness-2.46/MANIFEST 2005-04-28 19:20:38.000000000 -0700
@@ -27,6 +27,7 @@
t/strap-analyze.t
t/strap.t
t/test-harness.t
+t/verbose.t
t/lib/Dev/Null.pm
t/lib/if.pm
@@ -63,5 +64,6 @@
t/sample-tests/todo
t/sample-tests/todo_inline
t/sample-tests/too_many
+t/sample-tests/verbose
t/sample-tests/vms_nit
t/sample-tests/with_comments
diff -rN -u old-Test-Harness-2.46/bin/prove new-Test-Harness-2.46/bin/prove
--- old-Test-Harness-2.46/bin/prove 2005-04-28 19:22:21.000000000 -0700
+++ new-Test-Harness-2.46/bin/prove 2005-04-28 19:18:51.000000000 -0700
@@ -295,7 +295,10 @@
=head2 -v, --verbose
Display standard output of test scripts while running them. Also sets
-TEST_VERBOSE in case your tests rely on them.
+HARNESS_IS_VERBOSE in case your tests rely on them.
+
+=for deprecated
+It also sets TEST_VERBOSE
=head2 -V, --version
diff -rN -u old-Test-Harness-2.46/lib/Test/Harness/Straps.pm new-Test-Harness-2.46/lib/Test/Harness/Straps.pm
--- old-Test-Harness-2.46/lib/Test/Harness/Straps.pm 2005-04-28 19:22:21.000000000 -0700
+++ new-Test-Harness-2.46/lib/Test/Harness/Straps.pm 2005-04-28 19:17:03.000000000 -0700
@@ -280,7 +280,8 @@
print "# PERL5LIB=$ENV{PERL5LIB}\n";
}
- local $ENV{HARNESS_ACTIVE} = 1;
+ local $ENV{HARNESS_ACTIVE} = 1;
+ local $ENV{HARNESS_IS_VERBOSE} = $Test::Harness::Verbose || 0;
# *sigh* this breaks under taint, but open -| is unportable.
my $line = $self->_command_line($file);
diff -rN -u old-Test-Harness-2.46/lib/Test/Harness.pm new-Test-Harness-2.46/lib/Test/Harness.pm
--- old-Test-Harness-2.46/lib/Test/Harness.pm 2005-04-28 19:22:21.000000000 -0700
+++ new-Test-Harness-2.46/lib/Test/Harness.pm 2005-04-28 19:21:44.000000000 -0700
@@ -848,6 +848,11 @@
=head1 ENVIRONMENT
+=head2 Information for the tests
+
+These environment variables are set by Test::Harness so they can be read
+by tests run by Test::Harness.
+
=over 4
=item C<HARNESS_ACTIVE>
@@ -856,6 +861,20 @@
the tests to determine if they are being executed through the harness
or by any other means.
+=item C<HARNESS_IS_VERBOSE>
+
+If Harness is running in verbose mode (see C<$Verbose> and
+C<HARNESS_VERBOSE>) this will be true.
+
+=back
+
+
+=head2 Changing the behavior of Test::Harness
+
+These can be set by the user to alter the behavior of Test::Harness.
+
+=over 4
+
=item C<HARNESS_COLUMNS>
This value will be used for the width of the terminal. If it is not
@@ -979,8 +998,6 @@
HARNESS_TODOFAIL to display TODO failures
-Add a test for verbose.
-
Change internal list of test results to a hash.
Fix stats display when there's an overrun.
diff -rN -u old-Test-Harness-2.46/t/sample-tests/verbose new-Test-Harness-2.46/t/sample-tests/verbose
--- old-Test-Harness-2.46/t/sample-tests/verbose 1969-12-31 16:00:00.000000000 -0800
+++ new-Test-Harness-2.46/t/sample-tests/verbose 2005-04-28 19:14:34.000000000 -0700
@@ -0,0 +1,5 @@
+#!/usr/bin/perl -w
+
+print "1..1\n";
+my $ok = $ENV{HARNESS_IS_VERBOSE} ? '' : 'not ';
+print $ok . "ok 1\n";
diff -rN -u old-Test-Harness-2.46/t/test-harness.t new-Test-Harness-2.46/t/test-harness.t
--- old-Test-Harness-2.46/t/test-harness.t 2005-04-28 19:22:21.000000000 -0700
+++ new-Test-Harness-2.46/t/test-harness.t 2005-04-28 19:19:53.000000000 -0700
@@ -487,7 +487,7 @@
my $warning = '';
my $test_path = File::Spec->catfile($SAMPLE_TESTS, $test);
- print STDERR "# $test\n" if $ENV{TEST_VERBOSE};
+ print STDERR "# $test\n" if $ENV{HARNES_IS_VERBOSE};
eval {
select NULL; # _run_all_tests() isn't as quiet as it should be.
local $SIG{__WARN__} = sub { $warning .= join '', @_; };
diff -rN -u old-Test-Harness-2.46/t/verbose.t new-Test-Harness-2.46/t/verbose.t
--- old-Test-Harness-2.46/t/verbose.t 1969-12-31 16:00:00.000000000 -0800
+++ new-Test-Harness-2.46/t/verbose.t 2005-04-28 19:17:39.000000000 -0700
@@ -0,0 +1,37 @@
+#!/usr/bin/perl -w
+
+BEGIN {
+ if( $ENV{PERL_CORE} ) {
+ chdir 't';
+ @INC = ('../lib', 'lib');
+ }
+ else {
+ unshift @INC, 't/lib';
+ }
+}
+
+use Test::More 'no_plan';
+
+use Test::Harness;
+use File::Spec;
+use Dev::Null;
+
+tie *NULL, 'Dev::Null' or die $!;
+
+my $Curdir = File::Spec->curdir;
+my $SAMPLE_TESTS = $ENV{PERL_CORE}
+ ? File::Spec->catdir($Curdir, 'lib', 'sample-tests')
+ : File::Spec->catdir($Curdir, 't', 'sample-tests');
+
+my $test_path = File::Spec->catfile($SAMPLE_TESTS, "verbose");
+
+select NULL;
+
+{
+ local $Test::Harness::Verbose = 1;
+ my($totals, $failed) = Test::Harness::_run_all_tests($test_path);
+ ok( Test::Harness::_all_ok($totals) );
+}
+
+my($totals, $failed) = Test::Harness::_run_all_tests($test_path);
+ok( !Test::Harness::_all_ok($totals) );