Test::Some - test a subset of tests
version 0.2.1
use Test::More; use Test::Some 'foo'; plant tests => 3; subtest foo => sub { pass }; # will be skipped subtest bar => sub { fail };
This module allows to run a subset of the 'subtest' tests given in a test file.
The module declaration takes a whitelist of the subtests we want to run. Any subtest that doesn't match any of the whitelist items will be skipped (or potentially bypassed).
The test files don't even need to be modified, as the module can also be invoked from the command-line. E.g.,
$ perl -MTest::Some=foo t/tests.t
If no argument is given to the module declaration, the environment variable TEST_SOME will be used as the defaults. For example, this is equivalent to the example above:
TEST_SOME
$ export TEST_SOME=foo $ perl -MTest::Some t/tests.t
Tells Test::Some to bypass the non-whitelisted tests instead of skipping them. That makes for a smaller output, but the test file would now fail if it has a plan tests = $n> line (as we'll only report on $n - bypassed tests).
plan tests =
$n - bypassed
At its most simple, the names of the subtests we want to run can be passed.
# run subtests 'foo' and 'bar' use Test::Some 'foo', 'bar';
An item prefixed with a bang (!) is negated.
use Test::Some '!foo'; # run all tests but 'foo'
Note that a subtest is run if it matches any item in the whitelist, so
use Test::Some '!foo', '!bar';
will run all tests as `foo` is not `bar` and vice versa.
A string beginning with a slash (/), or a regular expression object will be considered to be a regular expression to be compared against the subtest name
use Test::Some '/foo'; # only tests with 'foo' in their name # equivalent to use Test::Some qr/foo/;
Strings prefixed with a colon (:) are considered to be tags.
# run all tests with the 'basic' tag use Test::Some ':basic';
Tags can be assigned to a subtest by putting them after the coderef. E.g.,
subtest foo, sub { ... }, 'tag1', 'tag2';
Test::More's subtest ignore those trailing arguments, so they be put there without breaking backward compatibility. If you want to give more visibility to those tags, you can also do
subtest foo => $_, 'tag1', 'tag2', for sub { ...; };
(that neat trick, incidentally, was pointed out by aristotle)
A coderef can be passed. It'll have the subtest name and its tags passed in as $_ and %_, respectively.
$_
%_
# run tests with tags 'important' *and* 'auth' use Test::Some sub { $_{important} and $_{auth} };
* http://techblog.babyl.ca/entry/test-some - introduction blog entry
Yanick Champoux <yanick@cpan.org>
This software is copyright (c) 2015 by Yanick Champoux.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Test::Some, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Some
CPAN shell
perl -MCPAN -e shell install Test::Some
For more information on module installation, please visit the detailed CPAN module installation guide.