Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Easy test management

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

Description:

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);

GetOptions(
    '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;

BEGIN {
    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 );


__END__

=head1 NAME

testall -- A test harness utility

=head1 SYNOPSIS

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

Options:

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

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

=head1 OVERVIEW

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>.

=head1 COMMAND LINE OPTIONS

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

=head2 --include

Use this to specify which files will be run as tests.  If used, only f
+iles
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
+e
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.
+t':

 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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (11)
As of 2014-07-31 04:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (244 votes), past polls