SPUG: Suggestions for Testing scripts

BenRifkah Bergsten-Buret benb at speakeasy.net
Thu Jun 15 13:50:27 PDT 2006

Satish Gupta wrote:
> I have some data processing scripts, not modules, in a directory. 
> These scripts use File::Spec to "require" other scripts and modules. 
> I'll like to develop some test-scripts to test these data processing 
> script and place them in a different directory, say "t".
> One way would have been to "require" the data processing script in 
> this test script but that will mess up the relative paths constructed 
> from File::Spec.
Just one of the pitfalls of using implicit relative paths.  I recommend 
switching to explicit paths defined as arguments or in a config file.  
Otherwise, have your test script cd into the appropriate directory 
before it runs the data processing script that it's testing.
> While you are at it, what is the correct syntax for:
> use if ($cond), Test::More tests => $Num_Tests;
It appears that you want to dynamically plan your number of tests based 
on a condition.  If this is the case check out the 'plan' function from 
Test::More.  Instead of:

use Test::More tests => $Num_Tests;

You can do:

use Test::More qw(no_plan);

# and later...

plan tests => $Num_Tests if $cond;

BenRifkah Bergsten-Buret,  Research Consultant
University of Washington
  * Biostatistics
    o Clinical Trials Center (CTC)
      + Resuscitation Outcomes Consortium (ROC)

More information about the spug-list mailing list