Skip Menu |

This queue is for tickets about the Test-Harness CPAN distribution.

Report information
The Basics
Id: 12457
Status: resolved
Priority: 0/
Queue: Test-Harness

People
Owner: andy [...] hexten.net
Requestors:
Cc:
AdminCc:

Bug Information
Severity: Unimportant
Broken in: (no value)
Fixed in: (no value)



Subject: Only set HARNESS_ACTIVE when the test is run.
Test::Harness sets HARNESS_ACTIVE right when it loads. This could falsely tell a program that it is being run by TH when it actually is not. This patch makes TH set HARNESS_ACTIVE inside analyze_file() just before the test program is actually run. The need for t/print_env instead of a one liner is because of shell quoting rules. Normally one has to quote a one liner with double quotes to be cross platform but Unix does not like "print $ENV{HARNESS_ACTIVE}" so I wrote a little program to do it.
Thu Apr 28 18:46:25 PDT 2005 schwern@pobox.com * Do not set HARNESS_ACTIVE when TH loads diff -rN -u old-Test-Harness-2.46/MANIFEST new-Test-Harness-2.46/MANIFEST --- old-Test-Harness-2.46/MANIFEST 2005-04-28 18:48:14.000000000 -0700 +++ new-Test-Harness-2.46/MANIFEST 2005-04-28 18:46:17.000000000 -0700 @@ -16,10 +16,12 @@ t/base.t t/callback.t t/harness.t +t/harness_active.t t/inc_taint.t t/nonumbers.t t/ok.t t/pod.t +t/print_env t/prove-globbing.t t/prove-switches.t t/strap-analyze.t 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 18:48:14.000000000 -0700 +++ new-Test-Harness-2.46/lib/Test/Harness/Straps.pm 2005-04-28 18:27:44.000000000 -0700 @@ -280,6 +280,8 @@ print "# PERL5LIB=$ENV{PERL5LIB}\n"; } + local $ENV{HARNESS_ACTIVE} = 1; + # *sigh* this breaks under taint, but open -| is unportable. my $line = $self->_command_line($file); unless( open(FILE, "$line|") ) { 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 18:48:14.000000000 -0700 +++ new-Test-Harness-2.46/lib/Test/Harness.pm 2005-04-28 18:27:56.000000000 -0700 @@ -38,12 +38,6 @@ *switches = *Switches; *debug = *Debug; -$ENV{HARNESS_ACTIVE} = 1; - -END { - # For VMS. - delete $ENV{HARNESS_ACTIVE}; -} # Some experimental versions of OS/2 build have broken $? my $Ignore_Exitcode = $ENV{HARNESS_IGNORE_EXITCODE}; diff -rN -u old-Test-Harness-2.46/t/harness_active.t new-Test-Harness-2.46/t/harness_active.t --- old-Test-Harness-2.46/t/harness_active.t 1969-12-31 16:00:00.000000000 -0800 +++ new-Test-Harness-2.46/t/harness_active.t 2005-04-28 18:43:58.000000000 -0700 @@ -0,0 +1,32 @@ +#!/usr/bin/perl -w + +BEGIN { + if( $ENV{PERL_CORE} ) { + chdir 't'; + @INC = ('../lib', 'lib'); + } + else { + unshift @INC, 't/lib'; + } +} +chdir 't'; + +use strict; +use Test::More; + +if( $ENV{PERL_CORE} ) { + plan skip_all => + "Core might run this with t/TEST which does not set HARNESS_ACTIVE"; +} +else { + plan tests => 2; +} + +ok $ENV{HARNESS_ACTIVE}, "Test::Harness sets HARNESS_ACTIVE"; + +my $is_active = qx{$^X "-I../lib" "-MTest::Harness" "--" print_env HARNESS_ACTIVE}; +chomp $is_active; +ok !$is_active, 'loading TH does not set HARNESS_ACTIVE'; + + + diff -rN -u old-Test-Harness-2.46/t/print_env new-Test-Harness-2.46/t/print_env --- old-Test-Harness-2.46/t/print_env 1969-12-31 16:00:00.000000000 -0800 +++ new-Test-Harness-2.46/t/print_env 2005-04-28 18:43:41.000000000 -0700 @@ -0,0 +1,3 @@ +#!/usr/bin/perl -l + +print $ENV{shift};
Fixed in 2.99, thanks.