Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Easy test management

by Ovid (Cardinal)
on Apr 03, 2003 at 23:24 UTC ( #247931=snippet: print w/ replies, xml ) Need Help??


Quite frequently while running tests, I find that it might be useful to skip a test or two while running through the full tests suite (maybe they take too long, for example). The following snippet allows more precise control over which tests I want to run at a given time.

You do write tests, don't you? :) (and thanks to Koschei for catching the typo in the POD)

#!/usr/bin/perl -w
use strict;
use Test::Harness;
use Getopt::Long;
use Pod::Usage;

my (@exclude,@include);

    'help|?'    => sub { pod2usage(-verbose => 2); exit },
    'verbose!'  => \$Test::Harness::verbose,
    'quiet'     => sub { $Test::Harness::verbose = 0 },
    'include=s' => \@include,
    'exclude=s' => \@exclude

@include = map { glob } @include;
@exclude = map { glob } @exclude;

    chdir 't' if -d 't';

my @files = @include;

unless (@files) {
    @files = glob "*.t";

my @tests;
foreach my $file ( sort @files ) {
    push @tests => $file unless grep { /\Q$file\E/ } @exclude;
runtests( @tests );


=head1 NAME

testall -- A test harness utility


B<testall --help> for more information
    testall [options]


    --help         Display POD
    --?            Same as --help
    --verbose      Display standard output of test scripts while runni
    --noverbose    Turn off --verbose (default Test::Harness behavior)
    --quiet        Same as --noverbose

    --include      Tests to include
    --exclude      Tests to exclude


This program uses C<Test::Harness> to run the results of a test suite.
+  With no
arguments, it will run all tests in the current directory (assumes tes
+t have a
C<.t> extension).

Shell metacharacters may be used with command lines options and will b
+e exanded 
via C<glob>.


Note that all options may be specified with a single dash and the firs
letter of the option.

=head2 --include

Use this to specify which files will be run as tests.  If used, only f
specified with C<--include> will be run.

 testall -i 02saleitem.t -i 02saletax.t -i 02saletender.t

The above may be written as (note the quotes):

 testall -i '02sale*.t'

=head2 --exclude

Use this switch to specify which files will not be run as tests.  If u
+sed, the
program assumes all files ending in C<.t> are tests and will skip thos
+e that
match C<--exclude>.  To run all tests but exclude the tests used in th
previous example:

 testall -e 02saleitem.t -e 02saletax.t -e 02saletender.t

The above may be written as:

 testall -e '02sale*'

The C<--exclude> and C<--include> options may be combined.  To run all
+ tests
containing the word 'product' in the filename, but skip 'productfinal.

 testall -i '*product*.t' -e productfinal.t
Comment on Easy test management
Download Code
Re: Easy test management
by Koschei (Monk) on Apr 04, 2003 at 00:38 UTC
    "The above may be written as (note the parentheses)"

    Erm, ITYM to "note the quotes"

Back to Snippets Section

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://247931]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (10)
As of 2015-04-27 14:14 GMT
Find Nodes?
    Voting Booth?

    Who makes your decisions?

    Results (505 votes), past polls