Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Think about Loose Coupling
 
PerlMonks

Easy test management

by Ovid (Archbishop)
 | Log in | Create a new user | The Monastery Gates | Super Search | 
 | Seekers of Perl Wisdom | Meditations | PerlMonks Discussion | 
 | Obfuscation | Reviews | Cool Uses For Perl | Perl News | Q&A | Tutorials | 
 | Poetry | Recent Threads | Newest Nodes | Donate | What's New | 

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

Login:
Password
remember me
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 making s'mores by the fire in the courtyard of the Monastery: (13)
GrandFather
atcroft
kennethk
herveus
dHarry
Ratazong
jkva
ssandv
stefbv
Lady_Aleena
wrinkles
AndyZaft
Neighbour
As of 2010-09-09 07:00 GMT
Sections?
Seekers of Perl Wisdom
Cool Uses for Perl
Meditations
PerlMonks Discussion
Categorized Q&A
Tutorials
Obfuscated Code
Perl Poetry
Perl News
See About the sections of PerlMonks
Information?
PerlMonks FAQ
Guide to the Monastery
What's New at PerlMonks
Voting/Experience System
Tutorials
Reviews
Library
Perl FAQs
Other Info Sources
Find Nodes?
Nodes You Wrote
Super Search
List Nodes By Users
Newest Nodes
Recently Active Threads
Selected Best Nodes
Best Nodes
Worst Nodes
Saints in our Book
Leftovers?
The St. Larry Wall Shrine
Offering Plate
Awards
Craft
Snippets Section
Code Catacombs
Quests
Editor Requests
Buy PerlMonks Gear
PerlMonks Merchandise
Planet Perl
Perlsphere
Use Perl
Perl.com
Perl 5 Wiki
Perl Jobs
Perl Mongers
Perl Directory
Perl documentation
CPAN
Random Node
Voting Booth?

My favourite poll on PerlMonks is ...

Your first Perl Book - the first one ever
Average number of caffeinated beverages per work day - the poll with the highest participation
My Thoughts on the New Voting/Experience System - the poll with the fewest votes cast
When I grow up, I want to be: - one of the polls with the fewest options
Perl 6 will primarily be: - the first one on Perl6
When I see a poll - one of the many polls about polls
this poll ;-)
yet to come
none - I hate polls. Bah.
some other

Results (130 votes), past polls