Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

merlyn (47)

merlyn
  merlyn@stonehenge.com
http://www.stonehenge.com/merlyn/
AOL IM: realmerlyn (Add Buddy, Send Message)
Yahoo! ID: realmerlyn (Add User, Send Message)

PAUSE-ID: MERLYN [cpan.org].
See my home page [stonehenge.com].

Journal of merlyn (47)

Tuesday April 29, 2003
11:50 AM

Skip tests if/unless $ENV{FOO} is set using Test::More

[ #11908 ]
There are a few CPAN modules that have excessive testing time when being installed (or reinstalled). Hint: if it takes more than a minute or two, I'm likely to be irritated.

In class today, it occurred to me that these tests could be conditional upon the presence or absence of an environment variable:

use Test::More tests => 120;

...

SKIP: {
  skip "skipping really long tests", 95
    unless $ENV{ALL_TESTS};
  ... 95 tests here ...
}

That way, the developer can capture the full test suite for development and maintenance, but as an installer, I don't have to sit through the whole thing, and I can know just how little I can get away with for a first-order "ok to install" test.

Please consider this if you're a module author. Be kind to your remote installer person.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • by Theory (10) on 2003.04.29 12:00 (#19576) Homepage Journal

    Actually, lots of CPAN modules do this already. All of the DBDs, for example, rely on the presence of environment variables in order to fully test their abilities to connect to databases. Similarly, HTML::Mason requires an environment variable for testing its ApacheHandler (since you can install and use Mason without mod_perl, if you like). And my App::Info module takes this approach so as to avoid testing values that may be different on a user's box than they would be on my own box.

    That said, I agree that it should probably be trumpeted more loudly and the word got out to more people. OTOH, sometimes long tests are necessary, and having people run them when they install CPAN modules is the best way to smoke out issues with one's modules. If you don't want to wait, don't make test.

    --David

    .
  • Similar (Score:5, Interesting)

    by Ovid (2709) on 2003.04.29 12:18 (#19578) Homepage Journal

    For some of our longer running tests at work, I check for an environment variable named "FAST_TESTS" and skip long running tests using that. The start of my test_all program looks like this (and takes a -f as an argument for fast tests)

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

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