Quite often people will write code which tests to see if
$ENV{HARNESS_ACTIVE} is true.  For example, this allows them to not
email support from their code while testing.  This variable is set in
Test::Harness.  However, this causes a problem when someone
accidentally does this:

  perl t/email_support.t

You can verify this behavior by running this with 'perl' and 'prove'. 
It will fail when run through Perl.

  use Test::More tests => 1;
  ok $ENV{HARNESS_ACTIVE}, 'running in the test harness';

Since I have ',r' and ',t' bound to ':!perl  %<cr>' and ':!prove -lv
%<cr>' in vim, it's easy for me to mistype this since those keys are
next to each other.

I am going to add the HARNESS_ACTIVE environment variable to
TAPx::Harness, but having something like $ENV{RUNNING_TESTS} in
Test::Builder so that users can be trained to know if tests are really
running or not.  As a workaround, you can fake it with this:

  package My::Test::More;

  use Test::Builder::Module;
  @ISA = qw(Test::Builder::Module);
  use Test::More;

  @EXPORT = @Test::More::EXPORT;
  $ENV{HARNESS_ACTIVE} = 1;

  1;

And then just 'use My::Test::More tests => $tests' in your code.  That
will always set the environment variable and provide some measure of
safety.  That protects someone accidentally running 'perl t/test.t',
but clearly the harness really isn't active then, so it's a bit of a
hack.

Thoughts?

Cheers,
Ovid

--

Buy the book -- http://www.oreilly.com/catalog/perlhks/
Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/

Reply via email to