[crap, accidentally replied only to Ovid .... trying again]

Ovid,

> If someone uses Test::Most and either has the environment DIE_ON_FAIL or 
> BAIL_ON_FAIL set to true, or has 'die' or 'bail' in the import list, they'll 
> likely be disappointed by failing test results sent back as they'll likely be 
> incomplete.

You know, we've just run into this in our $work environment as well.
I was setting up a test module to encourage test first development,
and my co-worker (Liz Cortell, a.k.a. zrusilla; I believe some of you
might know her) was setting up a test module for smoke testing ... so
my module using Test::Most with 'die' was somewhat antithetical to her
efforts. <g>

> What's the 'canonical' way to check to see if my tests are being run by a 
> smoker?  I can't find anything in Test::Smoke about this (I might be blind).

Are you considering changing Test::Most to try to solve this?  That
would be cool.  The solution I've implemented so far has just been to
take the 'die' out of Test::Most's import list and rely on the
environment variable.  I made a script which will run prove for me
(attached below for the curious); besides setting the env var for me,
it does a few other niceties.

But if you have an alternative solution, I'm all ears.


        -- Buddy


[This is my script, which I call just "t".  It's meant to be run
something either like "t testdir/", or "t SomeModule.pm" and then it
tries various schemes to figure out where the corresponding .t files
are.  It's also currently *nix-specific, just because I was too lazy
with the -n switch.  The extra blank lines at the top just help keep
the test runs separate.  It runs prove separately for each .t file
because otherwise the die-on-fail feature of Test::Most doesn't help
me much ... I would certainly welcome alternate solutions to _that_,
though, since obviously spawning a separate prove for each .t is
costly.]


#! /usr/bin/perl

use strict;
use warnings;

use Getopt::Std;


my $opt = {};
getopts("nh", $opt);

# help message
if ($opt->{h})
{
   my $me = $0;
   $me =~ [EMAIL PROTECTED]/@@;

   print STDERR "usage: $me -h | [-n] perl_module\n";
   print STDERR "       run tests associated with perl_module\n";
   print STDERR "           -h: this help message\n";
   print STDERR "           -n: only run the newest (most recently
modified) test\n";
   exit 2;
}


my $arg = shift;
my $dir;
if (-d $arg)
{
   $dir = $arg;
}
elsif ($arg =~ /^(.*)\.pm$// and -d "t/$1")
{
   $dir = "t/$1";
}
elsif ($arg = get_pkgname($arg) and -d "t/$arg")
{
   close(IN);
   $dir = "t/$arg";
}
else
{
   die("$0: cannot figure out where test files are\n");
}

$ENV{DIE_ON_FAIL} = 1;
print "\n" x 10;

chdir $dir or die "can't go to $dir";
if ($opt->{n})
{
   my $latest = `/bin/ls -1t *.t | head -n1`;
   chomp $latest;

   !system("prove $latest") or exit 1;
}
else
{
   foreach (glob("*.t"))
   {
       !system("prove $_") or exit 1;
   }
}


sub get_pkgname
{
   my $pkg;

   open(IN, $_[0]);
   while ( <IN> )
   {
       if ( /package\s+(.*?);/ )
       {
           $pkg = $1;
           $pkg =~ s/::/-/g;
           last;
       }
   }
   close(IN);

   return $pkg;
}

Reply via email to