1Test::Some(3) User Contributed Perl Documentation Test::Some(3)
2
3
4
6 Test::Some - test a subset of tests
7
9 version 0.2.1
10
12 use Test::More;
13
14 use Test::Some 'foo';
15
16 plant tests => 3;
17
18 subtest foo => sub { pass };
19
20 # will be skipped
21 subtest bar => sub { fail };
22
24 This module allows to run a subset of the 'subtest' tests given in a
25 test file.
26
27 The module declaration takes a whitelist of the subtests we want to
28 run. Any subtest that doesn't match any of the whitelist items will be
29 skipped (or potentially bypassed).
30
31 The test files don't even need to be modified, as the module can also
32 be invoked from the command-line. E.g.,
33
34 $ perl -MTest::Some=foo t/tests.t
35
36 If no argument is given to the module declaration, the environment
37 variable "TEST_SOME" will be used as the defaults. For example, this is
38 equivalent to the example above:
39
40 $ export TEST_SOME=foo
41 $ perl -MTest::Some t/tests.t
42
43 Whitelist items
44 '~'
45
46 Tells Test::Some to bypass the non-whitelisted tests instead of
47 skipping them. That makes for a smaller output, but the test file would
48 now fail if it has a "plan tests =" $n> line (as we'll only report on
49 "$n - bypassed" tests).
50
51 Subtest name
52
53 At its most simple, the names of the subtests we want to run can be
54 passed.
55
56 # run subtests 'foo' and 'bar'
57 use Test::Some 'foo', 'bar';
58
59 Negation
60
61 An item prefixed with a bang (!) is negated.
62
63 use Test::Some '!foo'; # run all tests but 'foo'
64
65 Note that a subtest is run if it matches any item in the whitelist, so
66
67 use Test::Some '!foo', '!bar';
68
69 will run all tests as `foo` is not `bar` and vice versa.
70
71 Regular expression
72
73 A string beginning with a slash (/), or a regular expression object
74 will be considered to be a regular expression to be compared against
75 the subtest name
76
77 use Test::Some '/foo'; # only tests with 'foo' in their name
78
79 # equivalent to
80 use Test::Some qr/foo/;
81
82 Tags
83
84 Strings prefixed with a colon (:) are considered to be tags.
85
86 # run all tests with the 'basic' tag
87 use Test::Some ':basic';
88
89 Tags can be assigned to a subtest by putting them after the coderef.
90 E.g.,
91
92 subtest foo, sub {
93 ...
94 }, 'tag1', 'tag2';
95
96 Test::More's subtest ignore those trailing arguments, so they be put
97 there without breaking backward compatibility. If you want to give more
98 visibility to those tags, you can also do
99
100 subtest foo => $_, 'tag1', 'tag2', for sub {
101 ...;
102 };
103
104 (that neat trick, incidentally, was pointed out by aristotle)
105
106 Code
107
108 A coderef can be passed. It'll have the subtest name and its tags
109 passed in as $_ and %_, respectively.
110
111 # run tests with tags 'important' *and* 'auth'
112 use Test::Some sub {
113 $_{important} and $_{auth}
114 };
115
117 * <http://techblog.babyl.ca/entry/test-some> - introduction blog entry
118
120 Yanick Champoux <yanick@cpan.org>
121
123 This software is copyright (c) 2015 by Yanick Champoux.
124
125 This is free software; you can redistribute it and/or modify it under
126 the same terms as the Perl 5 programming language system itself.
127
128
129
130perl v5.32.1 2021-01-27 Test::Some(3)