lib/Test2/Aggregate.pm

filter: Statementstmt 100% 202 / 202 Branchbran 97.1% 134 / 138 Conditioncond 92.3% 36 / 39 MC/DCmcdc 87.5% 21 / 24 Subroutinesub 100% 28 / 28 Podpod 100% 1 / 1 totaltotal 97.6% 422 / 432 CC 91 SCAR 26.6
CC
91
Cov
98%
run_tests
30.1
_run_tests
22.0
__ANON__
8.0
CRAP 14.3
↑ Summary blib/lib/Test2/Aggregate/Helper.pm »
1 package Test2::Aggregate;
2  
3 43 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 43 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 43 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 43 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 43 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 43 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 43 ▶use Test2::V0 'subtest';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 =head1 NAME
14  
15 Test2::Aggregate - Aggregate tests for increased speed
16  
17 =head1 SYNOPSIS
18  
19 use Test2::Aggregate;
20 use Test2::V0; # Or 'use Test::More' etc if your suite uses an other framework
21  
22 Test2::Aggregate::run_tests(
23 dirs => [@test_dirs_or_files]
24 );
25  
26 done_testing();
27  
28 =head1 VERSION
29  
30 See C<$VERSION> in module.
31  
32 =cut
33  
34 26 our $VERSION = '1.00';
35  
36 =head1 DESCRIPTION
37  
38 Aggregates all tests specified with C<dirs> (which can even be individual tests)
39 to avoid forking, reloading etc. that can help with performance (dramatically if
40 you have numerous small tests) and also facilitate group profiling. It is quite
41 common to have tests that take over a second of startup time for milliseconds of
42 actual runtime - L<Test2::Aggregate> removes that overhead.
43 Test files are expected to end in B<.t> and are run as subtests of a single
44 aggregate test.
45  
46 A bit similar (mainly in intent) to L<Test::Aggregate>, but no inspiration was
47 drawn from the specific module, so simpler in concept and execution, which
48 makes it much more likely to work with your test suite (especially if you use modern
49 tools like L<Test2::Suite>). It does not even try to package each test by default
50 (there is an option), which may be good or bad, depending on your requirements.
51  
52 Generally, the way to use this module is to try to aggregate sets of quick tests
53 (e.g. unit tests). Try to iteratively add tests to the aggregator, using the C<lists>
54 option, so you can easily edit and remove those that do not work. Trying an entire,
55 large, suite in one go is not a good idea, as an incompatible test can break the
56 run making the subsequent tests fail (especially when doing things like globally
57 redefining built-ins etc.) - see the module usage notes for help.
58  
59 The module can work with L<Test::Builder> / L<Test::More> suites, but you will
60 have less issues with L<Test2::Suite> (see notes).
61  
62 =head1 METHODS
63
64 =head2 C<run_tests>
65  
66 my $stats = Test2::Aggregate::run_tests(
67 dirs => \@dirs, # optional if lists defined
68 lists => \@lists, # optional if dirs defined
69 exclude => qr/exclude_regex/, # optional
70 include => qr/include_regex/, # optional
71 root => '/testroot/', # optional
72 load_modules => \@modules, # optional
73 package => 0, # optional
74 shuffle => 0, # optional
75 sort => 0, # optional
76 reverse => 0, # optional
77 unique => 1, # optional
78 repeat => 1, # optional, requires Test2::Plugin::BailOnFail for < 0
79 slow => 0, # optional
80 test_warnings => 0, # optional
81 override => \%override, # optional, requires Sub::Override
82 stats_output => $stats_output_path, # optional
83 extend_stats => 0, # optional
84 pass_only => 0, # optional
85 absolute => 0, # optional
86 bail_on_fail => 0, # optional, requires Test2::Plugin::BailOnFail
87 no_dot => 0, # optional
88 relative_root => 0, # optional
89 allow_errors => 0, # optional
90 pre_eval => $code_to_eval, # optional
91 dry_run => 0, # optional
92 recursion => 0, # optional
93 slurp_param => {binmode => $mode} # optional
94 );
95  
96 Runs the aggregate tests. Returns a hashref with stats like this:
97  
98 $stats = {
99 'test.t' => {
100 'test_no' => 1, # numbering starts at 1
101 'pass_perc' => 100, # for single runs pass/fail is 100/0
102 'timestamp' => '20190705T145043', # start of test
103 'time' => '0.1732', # seconds - only with stats_output
104 'warnings' => $STDERR # only with test_warnings on non empty STDERR
105 }
106 };
107  
108 The parameters to pass:
109  
110 =over 4
111
112 =item * C<dirs> (either this or C<lists> is required)
113  
114 An arrayref containing directories which will be searched recursively, or even
115 individual tests. The directories (unless C<shuffle> or C<reverse> are true)
116 will be processed and tests run in order specified. Test files are expected to
117 end in C<.t>.
118  
119 =item * C<lists> (either this or C<dirs> is required)
120  
121 Arrayref of flat files from which each line will be pushed to C<dirs> (so they
122 have a lower precedence - note C<root> still applies, don't include it in the
123 paths inside the list files). If the path does not exist, it will currently be
124 silently ignored, however the "official" way to skip a line without checking it
125 as a path is to start with a C<#> to denote a comment.
126  
127 This option is nicely combined with the C<--exclude-list> option of C<yath> (the
128 L<Test2::Harness>) to skip the individual runs of the tests you aggregated.
129  
130 =item * C<exclude> (optional)
131  
132 A regex to filter out tests that you want excluded.
133  
134 =item * C<include> (optional)
135  
136 A regex which the tests have to match in order to be included in the test run.
137 Applied after C<exclude>.
138  
139 =item * C<root> (optional)
140  
141 If defined, must be a valid root directory that will prefix all C<dirs> and C<lists>
142 items. You may want to set it to C<'./'> if you want dirs relative to the current
143 directory and the dot is not in your C<@INC>.
144  
145 =item * C<relative_root> (optional)
146  
147 Set to true if you want your root to be relative to the caller script's directory
148 (based on C<$0>). It is ignored if you use an absolute root path.
149  
150 =item * C<load_modules> (optional)
151  
152 Arrayref with modules to be loaded (with C<eval "use ...">) at the start of the
153 test. Useful for testing modules with special namespace requirements.
154  
155 =item * C<package> (optional)
156  
157 Will package each test in its own namespace. While it may help avoid things like
158 redefine warnings, from experience, it can break some tests, so it is disabled
159 by default.
160  
161 =item * C<override> (optional)
162  
163 Pass L<Sub::Override> compatible key/values as a hashref.
164  
165 =item * C<repeat> (optional)
166  
167 Number of times to repeat the test(s) (default is 1 for a single run). If
168 C<repeat> is negative, L<Test2::Plugin::BailOnFail> is required, as the tests
169 will repeat until they bail on a failure. It can be combined with C<test_warnings>
170 in which case a warning will also cause the test run to end.
171  
172 =item * C<unique> (optional)
173  
174 From v0.11, duplicate tests are by default removed from the running list as that
175 could mess up the stats output. You can still define it as false to allow duplicate
176 tests in the list.
177  
178 =item * C<sort> (optional)
179  
180 Sort tests alphabetically if set to true. Provides a way to fix the test order
181 across systems.
182  
183 =item * C<shuffle> (optional)
184  
185 Random order of tests if set to true. Will override C<sort>.
186 Uses C<List::Util::shuffle>, so is affected by the C<$RAND> variable.
187  
188 =item * C<reverse> (optional)
189  
190 Reverse order of tests if set to true.
191  
192 =item * C<slow> (optional)
193  
194 When true, tests will be skipped if the environment variable C<SKIP_SLOW> is set.
195  
196 =item * C<test_warnings> (optional)
197  
198 Tests for warnings over all the tests if set to true - this is added as a final
199 test which expects zero as the number of tests which had STDERR output.
200 The STDERR output of each test will be printed at the end of the test run (and
201 included in the test run result hash), so if you want to see warnings the moment
202 they are generated leave this option disabled.
203  
204 =item * C<allow_errors> (optional)
205  
206 If enabled, it will allow errors that exit tests prematurely (so they may return
207 a pass if one of their subtests had passed). The option is available to enable
208 old behaviour (version <= 0.12), before the module stopped allowing this.
209  
210 =item * C<dry_run> (optional)
211  
212 Instead of running the tests, will do C<ok($testname)> for each one. Otherwise,
213 test order, stats files etc. will be produced (as if all tests passed).
214  
215 =item * C<slurp_param> (optional)
216  
217 If you are using list files, by default, C<Path::Tiny::slurp_utf8> will be used
218 to read them.
219 If you would like to use C<slurp> with your own parameters instead, like a UTF16
220 binmode etc, you can pass them here.
221  
222 =item * C<pre_eval> (optional)
223  
224 String with code to run with eval before each test. You might be inclined to do
225 this for example:
226  
227 pre_eval => "no warnings 'redefine';"
228  
229 You might expect it to silence redefine warnings (when you have similarly named
230 subs on many tests), but even if you don't set warnings explicitly in your tests,
231 most test bundles will set warnings automatically for you (e.g. for L<Test2::V0>
232 you'd have to do C<use Test2::V0 -no_warnings =E<gt> 1;> to avoid it).
233  
234 =item * C<stats_output> (optional)
235  
236 C<stats_output> specifies a path where a file will be created to print out
237 running time per test (average if multiple iterations) and passing percentage.
238 With C<repeat == 1>, output is written after each test in execution order, so
239 completed results survive an interrupted run. With C<repeat E<gt> 1>, averages
240 are written from slowest test to fastest after all iterations complete.
241 On negative C<repeat>, each iteration streams its own statistics.
242 The name of the file is C<caller_script-YYYYMMDDTHHmmss.txt>.
243 If C<'-'> is passed instead of a path, then the output will be written to STDOUT.
244 The timing stats are useful because the test harness doesn't normally measure
245 time per subtest (remember, your individual aggregated tests become subtests).
246 If you prefer to capture the hash output of the function and use that for your
247 reports, you still need to define C<stats_output> to enable timing (just send
248 the output to C</dev/null>, C</tmp> etc).
249  
250 =item * C<extend_stats> (optional)
251  
252 This option exist to make the default output format of C<stats_output> be fixed,
253 but still allow additions in future versions that will only be written with the
254 C<extend_stats> option enabled.
255 Additions with C<extend_stats> as of the current version:
256  
257 =over 4
258  
259 =item * starting date/time in ISO_8601.
260  
261 =back
262  
263 =item * C<pass_only> (optional)
264  
265 Modifies C<stats_output> by making it only print out a list of passing tests.
266 Useful for creating lists of aggregateable tests. With C<test_warnings>, tests
267 that produced warnings are not considered passing.
268 Has no effect if C<stats_output> is not defined.
269  
270 =item * C<absolute> (optional)
271  
272 Matches pre-1.00 behaviour by including C<root> in the output of stats.
273  
274 =item * C<no_dot> (optional)
275  
276 Current version will add a C<./> at the start of a test file if the full path does
277 not start with C</> or C<.> to avoid the C<'.' is no longer in @INC> error.
278 Setting C<no_dot> to true matches pre-1.00 behaviour that did not do this.
279  
280 =item * C<bail_on_fail> (optional)
281  
282 Will bail (exit) on first test failure. It is implied for repeat < 0.
283 Requires L<Test2::Plugin::BailOnFail>; a missing plugin is a fatal error.
284  
285 =item * C<recursion> (optional)
286  
287 Setting it to 1 will allow recursion. By default, if C<$ENV{AGGREGATE_TESTS}> is
288 true, C<run_tests> will skip the tests to avoid running under a parent aggregator
289 C<run_tests>.
290  
291 =back
292  
293 =cut
294  
295 134 ▶sub run_tests {
Subroutine run_tests: called CC=30 SCAR=34.0
Pod documented
296 68 my %args = @_;
297  
298 Test2::V0::plan skip_all => 'Skipping slow tests.'
299 68 ▶ if $args{slow} && $ENV{SKIP_SLOW};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"slow"} and $ENV{"SKIP_SLOW"} 1 71 72
Condition100%3/3
$args{"slow"} and $ENV{"SKIP_SLOW"}
!ll&&!rl&&r
7011
MC/DC100%2/2
$args{"slow"} and $ENV{"SKIP_SLOW"}
$args{"slow"} $ENV{"SKIP_SLOW"}
Truth table100%3/3
A and B
A= $args{"slow"}B= $ENV{"SKIP_SLOW"}
ABresult
0X0
100
111
300  
301 Test2::V0::plan skip_all => 'Skipping aggregator recursion.'
302 68 ▶ if !$args{recursion} && $ENV{AGGREGATE_TESTS};
Branch: 1 branch
BranchTrueFalseTotal
if not $args{"recursion"} and $ENV{"AGGREGATE_TESTS"} 0 71 71
Condition33%1/3
not $args{"recursion"} and $ENV{"AGGREGATE_TESTS"}
!ll&&!rl&&r
0710
MC/DC0%0/2
not $args{"recursion"} and $ENV{"AGGREGATE_TESTS"}
not $args{"recursion"} $ENV{"AGGREGATE_TESTS"}
Truth table33%1/3
not(A) and B
A= not $args{"recursion"}B= $ENV{"AGGREGATE_TESTS"}
ABresult
0X0
100
111
303  
304 68 eval "use $_;" foreach @{$args{load_modules}};
305 68 local $ENV{AGGREGATE_TESTS} = 1;
306  
307 71 ▶ my $override = $args{override} ? _override($args{override}) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$args{'override'} ? : 1 70 71
308 71 my @dirs = ();
309 41 ▶ $args{root} ||= '';
Condition100%2/2
$args{"root"} ||= ""
l!l
3041
MC/DC100%1/1
$args{"root"} ||= ""
$args{"root"}
Truth table100%2/2
A
A= $args{"root"}
Aresult
11
00
310 71 my @tests;
311  
312 71 ▶ @dirs = @{$args{dirs}} if $args{dirs};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"dirs"} 37 34 71
313 19 ▶ $args{root} .= '/' unless !$args{root} || $args{root} =~ m#/$#;
Branch: 1 branch
BranchTrueFalseTotal
unless not $args{"root"} or $args{"root"} =~ m[/$] 26 45 71
Condition100%3/3
not $args{"root"} or $args{"root"} =~ m[/$]
l!l&&r!l&&!r
41426
MC/DC100%2/2
not $args{"root"} or $args{"root"} =~ m[/$]
not $args{"root"} $args{"root"} =~ m[/$]
Truth table100%3/3
not(A) or B
A= not $args{"root"}B= $args{"root"} =~ m[/$]
ABresult
1X1
011
000
314 $args{root} = dirname($0) . "/$args{root}"
315 71 ▶ if $args{relative_root} && $args{root} && $args{root} !~ m#^/#;
Branch: 1 branch
BranchTrueFalseTotal
if $args{"relative_root"} and $args{"root"} and not $args{"root"} =~ m[^/] 24 47 71
Condition83%5/6
$args{"relative_root"} and $args{"root"} and not $args{"root"} =~ m[^/]
!ll&&!rl&&r
46124
$args{"relative_root"} and $args{"root"}
!ll&&!rl&&r
46025
MC/DC66%2/3
$args{"relative_root"} and $args{"root"} and not $args{"root"} =~ m[^/]
$args{"relative_root"} $args{"root"} not $args{"root"} =~ m[^/]
Truth table75%3/4
A and B and not(C)
A= $args{"relative_root"}B= $args{"root"}C= not $args{"root"} =~ m[^/]
ABCresult
0XX0
10X0
1100
1111
316  
317 71 ▶ if ($args{root} && ! -e $args{root}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'root'} and not -e $args{'root'}) { } 2 69 71
Condition100%3/3
$args{"root"} and not -e $args{"root"}
!ll&&!rl&&r
41282
MC/DC100%2/2
$args{"root"} and not -e $args{"root"}
$args{"root"} not -e $args{"root"}
Truth table100%3/3
A and not(B)
A= $args{"root"}B= not -e $args{"root"}
ABresult
0X0
100
111
318 36 warn "Root '$args{root}' does not exist, no tests are loaded."
319 } else {
320 86 foreach my $file (@{$args{lists}}) {
321 push @dirs,
322 96 ▶ map {/^\s*(?:#|$)/ ? () : $_}
Branch: 1 branch
BranchTrueFalseTotal
/^\s*(?:#|$)/ ? : 26 62 88
323 split(/\r?\n/,
324 84 _read_file($args{root}, $file, $args{slurp_param}));
325 }
326  
327 find(
328 154 ▶ sub {push @tests, $File::Find::name if /\.t$/},
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if /\.t$/ 125 56 181
329 69 ▶ grep {-e} map {_check_abs_path($args{root}, $_)} @dirs
Branch: 1 branch
BranchTrueFalseTotal
if @dirs 68 1 69
330 )
331 if @dirs;
332 }
333  
334 71 ▶ $args{unique} = 1 unless defined $args{unique};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"unique"} 70 1 71
335 67 ▶ $args{repeat} ||= 1;
Condition100%2/2
$args{"repeat"} ||= 1
l!l
962
MC/DC100%1/1
$args{"repeat"} ||= 1
$args{"repeat"}
Truth table100%2/2
A
A= $args{"repeat"}
Aresult
11
00
336  
337 67 _process_run_order(\@tests, \%args);
338  
339 71 my @stack = caller();
340 70 ▶ $args{caller} = $stack[1] || 'aggregate';
Condition100%2/2
$stack[1] || 'aggregate'
l!l
701
MC/DC100%1/1
$stack[1] || 'aggregate'
$stack[1]
Truth table100%2/2
A
A= $stack[1]
Aresult
11
00
341 38 $args{caller} =~ s#^.*?([^/]+)$#$1#;
342  
343 71 my $warnings = [];
344 20 ▶ if ($args{bail_on_fail} || $args{repeat} < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"bail_on_fail"} or $args{"repeat"} < 0) 27 44 71
Condition100%3/3
$args{"bail_on_fail"} or $args{"repeat"} < 0
l!l&&r!l&&!r
24344
MC/DC100%2/2
$args{"bail_on_fail"} or $args{"repeat"} < 0
$args{"bail_on_fail"} $args{"repeat"} < 0
Truth table100%3/3
A or B
A= $args{"bail_on_fail"}B= $args{"repeat"} < 0
ABresult
1X1
011
000
345 60 ▶ eval 'use Test2::Plugin::BailOnFail; 1' or die $@;
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
eval "use Test2::Plugin::BailOnFail; 1" or die $@ 27 0 27
346 }
347 20 ▶ if ($args{repeat} < 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'repeat'} < 0) { } 3 68 71
elsif ($args{'test_warnings'}) { } 9 59 68
348 7 my $iter = 0;
349 7 ▶ while (!@$warnings) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$warnings) 4 2 6
350 7 $iter++;
351 8 print "Test suite iteration $iter\n";
352 6 ▶ if ($args{test_warnings}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'test_warnings'}) { } 3 1 4
353 $warnings = _process_warnings(
354 106 ▶ Test2::V0::warnings{_run_tests(\@tests, \%args)},
Subroutine __ANON__: called CC=1 SCAR=0.0
355 9 \%args
356 );
357 } else {
358 49 _run_tests(\@tests, \%args);
359 }
360 }
361 } elsif ($args{test_warnings}) {
362 $warnings = _process_warnings(
363 110 ▶ Test2::V0::warnings { _run_tests(\@tests, \%args) },
Subroutine __ANON__: called CC=1 SCAR=0.0
364 48 \%args
365 );
366 48 Test2::V0::is(
367 @$warnings,
368 0,
369 'No warnings in the aggregate tests.'
370 );
371 } else {
372 124 _run_tests(\@tests, \%args);
373 }
374  
375 15 ▶ warn "Test warning output:\n".join("\n", @$warnings)."\n"
Branch: 1 branch
BranchTrueFalseTotal
if @$warnings 5 55 60
376 if @$warnings;
377  
378 17 return $args{stats};
379 }
380  
381 58 ▶sub _check_abs_path {
Subroutine _check_abs_path: called CC=3 SCAR=11.0
382 135 my $root = shift;
383 62 my $path = shift;
384 # Can't use path() below as it removes ./ (required by absolute option)
385 62 ▶ $path = "$root$path" unless !$root || substr($path, 0, 1) eq '/';
Branch: 1 branch
BranchTrueFalseTotal
unless not $root or substr($path, 0, 1) eq "/" 58 76 134
Condition100%3/3
not $root or substr($path, 0, 1) eq "/"
l!l&&r!l&&!r
641258
MC/DC100%2/2
not $root or substr($path, 0, 1) eq "/"
not $root substr($path, 0, 1) eq "/"
Truth table100%3/3
not(A) or B
A= not $rootB= substr($path, 0, 1) eq "/"
ABresult
1X1
011
000
386 70 return $path;
387 }
388  
389 59 ▶sub _read_file {
Subroutine _read_file: called CC=2 SCAR=6.9
390 37 my $root = shift;
391 37 my $path = shift;
392 62 my $param = shift;
393 62 my $file = path(_check_abs_path($root, $path));
394  
395 62 ▶ return $param ? $file->slurp($param) : $file->slurp_utf8;
Branch: 1 branch
BranchTrueFalseTotal
$param ? : 1 36 37
396 }
397  
398 29 ▶sub _process_run_order {
Subroutine _process_run_order: called CC=7 SCAR=19.5
399 70 my $tests = shift;
400 67 my $args = shift;
401  
402 @$tests = grep(!_path_match($_, $args->{exclude}, $args->{root}), @$tests)
403 67 ▶ if $args->{exclude};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"exclude"} 3 68 71
404 @$tests = grep(_path_match($_, $args->{include}, $args->{root}), @$tests)
405 16 ▶ if $args->{include};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"include"} 3 68 71
406  
407 16 ▶ @$tests = _uniq(@$tests) if $args->{unique};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"unique"} 70 1 71
408  
409 18 ▶ if ($args->{shuffle}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args->{'shuffle'}) { } 1 70 71
elsif ($args->{'sort'}) { } 8 62 70
410 56 require List::Util;
411 15 @$tests = List::Util::shuffle @$tests;
412 } elsif ($args->{sort}) {
413 20 @$tests = sort @$tests;
414 }
415  
416 25 ▶ @$tests = reverse @$tests if $args->{reverse};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"reverse"} 2 69 71
417 }
418  
419 2 ▶sub _path_match {
Subroutine _path_match: called CC=2 SCAR=6.9
420 6 my ($test, $regex, $root) = @_;
421  
422 6 ▶ return 1 if $test =~ /$regex/;
Branch: 1 branch
BranchTrueFalseTotal
if $test =~ /$regex/ 5 6 11
423 2 return _test_name($test, $root) =~ /$regex/;
424 }
425  
426 65 ▶sub _process_warnings {
Subroutine _process_warnings: called CC=3 SCAR=11.0
427 12 my $warnings = shift;
428 12 my $args = shift;
429 17 my @warnings = split(/<-Test2::Aggregate\n/, join('',@$warnings));
430 11 my @clean = ();
431  
432 11 foreach my $warn (@warnings) {
433 29 ▶ if ($warn =~ m/(.*)->Test2::Aggregate\n(.*\S.*)/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($warn =~ /(.*)->Test2::Aggregate\n(.*\S.*)/s) 7 24 31
434 8 push @clean, "<$1>\n$2";
435 57 $args->{stats}->{$1}->{warnings} = $2;
436 57 $args->{stats}->{$1}->{pass_perc} = 0;
437 }
438 }
439 61 return \@clean;
440 }
441  
442 93 ▶sub _run_tests {
Subroutine _run_tests: called CC=22 SCAR=30.9
443 67 my $tests = shift;
444 67 my $args = shift;
445  
446 67 my $repeat = $args->{repeat};
447 67 ▶ $repeat = 1 if $repeat < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $repeat < 0 4 67 71
448 67 my (%stats, %warned, $start, $warned);
449  
450 # Track warnings per test, so stats written before the final warning
451 # processing (e.g. streamed pass_only) already see them. Installed once per
452 # run, not per test, so handlers that tests install (e.g. NoWarnings on
453 # first load) stay in place for the following tests.
454 66 ▶ local $SIG{__WARN__} = _warn_tracker(\$warned) if $args->{test_warnings};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"test_warnings"} 12 59 71
455  
456 73 ▶ require Time::HiRes if $args->{stats_output};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"stats_output"} 33 38 71
457 73 my $fh = _stats_fh($args);
458  
459 73 for my $i (1 .. $repeat) {
460 100 ▶ my $iter = $repeat > 1 ? "Iter: $i/$repeat - " : '';
Branch: 1 branch
BranchTrueFalseTotal
$repeat > 1 ? : 12 64 76
461 100 my $count = 1;
462 100 foreach my $test (@$tests) {
463 my $test_nm =
464 114 ▶ $args->{absolute} ? $test : _test_name($test, $args->{root});
Branch: 1 branch
BranchTrueFalseTotal
$args->{'absolute'} ? : 12 104 116
465  
466 114 ▶ warn "$test_nm->Test2::Aggregate\n" if $args->{test_warnings};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"test_warnings"} 32 84 116
467  
468 114 ▶ $stats{$test_nm}{test_no} = $count unless $stats{$test_nm}{test_no};
Branch: 1 branch
BranchTrueFalseTotal
unless $stats{$test_nm}{"test_no"} 102 14 116
469 114 ▶ $start = Time::HiRes::time() if $args->{stats_output};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"stats_output"} 47 69 116
470 114 $stats{$test_nm}{timestamp} = _timestamp();
471  
472 114 my $exec_error;
473 106 $warned = 0;
474 # aggit uses this marker to distinguish an interrupted test from
475 # harness startup errors and failures after the suite has finished.
476 path($args->{_progress_file})->spew_utf8("$test_nm\n")
477 106 ▶ if $args->{_progress_file};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"_progress_file"} 28 88 116
478 35 ▶ my $result = subtest $iter. "Running test $test_nm" => sub {
Subroutine __ANON__: called CC=8 SCAR=20.8
479 114 ▶ eval $args->{pre_eval} if $args->{pre_eval};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"pre_eval"} 2 114 116
480  
481 114 ▶ if ($args->{dry_run}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'dry_run'}) { } 2 114 116
482 79 Test2::V0::ok($test);
483 } else {
484 98 my $t= $test;
485 $t = "./$test"
486 100 ▶ unless $args->{no_dot} || $test =~ m#^[./]#;
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"no_dot"} or $test =~ m[^[./]] 71 43 114
Condition100%3/3
$args->{"no_dot"} or $test =~ m[^[./]]
l!l&&r!l&&!r
24171
MC/DC100%2/2
$args->{"no_dot"} or $test =~ m[^[./]]
$args->{"no_dot"} $test =~ m[^[./]]
Truth table100%3/3
A or B
A= $args->{"no_dot"}B= $test =~ m[^[./]]
ABresult
1X1
011
000
487 $args->{package}
488 39 ▶ ? eval "package Test::$i" . '::' . "$count; do '$t';"
Branch: 1 branch
BranchTrueFalseTotal
$args->{'package'} ? : 8 106 114
489 : do $t;
490 41 $exec_error = $@;
491 }
492 Test2::V0::is($exec_error, '', 'Execution should not fail/warn')
493 41 ▶ if !$args->{allow_errors} && $exec_error;
Branch: 1 branch
BranchTrueFalseTotal
if not $args->{"allow_errors"} and $exec_error 1 105 106
Condition100%3/3
not $args->{"allow_errors"} and $exec_error
!ll&&!rl&&r
31021
MC/DC100%2/2
not $args->{"allow_errors"} and $exec_error
not $args->{"allow_errors"} $exec_error
Truth table100%3/3
not(A) and B
A= not $args->{"allow_errors"}B= $exec_error
ABresult
0X0
100
111
494 106 };
495  
496 106 ▶ $warned{$test_nm} = 1 if $warned;
Branch: 1 branch
BranchTrueFalseTotal
if $warned 7 99 106
497 106 ▶ warn "<-Test2::Aggregate\n" if $args->{test_warnings};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"test_warnings"} 32 74 106
498  
499 $stats{$test_nm}{time} += (Time::HiRes::time() - $start)/$repeat
500 106 ▶ if $args->{stats_output};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"stats_output"} 38 68 106
501 106 ▶ $stats{$test_nm}{pass_perc} += $result ? 100/$repeat : 0;
Branch: 1 branch
BranchTrueFalseTotal
$result ? : 103 3 106
502 # Matches _process_warnings, which zeroes pass_perc on warnings
503 106 ▶ $stats{$test_nm}{pass_perc} = 0 if $warned{$test_nm};
Branch: 1 branch
BranchTrueFalseTotal
if $warned{$test_nm} 7 99 106
504 79 $count++;
505  
506 # If we have single iteration, no need to collect stats so write
507 # per line to avoid losing them in case of SIG
508 _print_stats($fh, \%stats, $args, $test_nm)
509 59 ▶ if $args->{stats_output} && $repeat == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"stats_output"} and $repeat == 1 34 72 106
Condition100%3/3
$args->{"stats_output"} and $repeat == 1
!ll&&!rl&&r
68434
MC/DC100%2/2
$args->{"stats_output"} and $repeat == 1
$args->{"stats_output"} $repeat == 1
Truth table100%3/3
A and B
A= $args->{"stats_output"}B= $repeat == 1
ABresult
0X0
100
111
510 path($args->{_progress_file})->spew_utf8('')
511 59 ▶ if $args->{_progress_file};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"_progress_file"} 19 87 106
512 }
513 }
514  
515 62 ▶ if ($args->{stats_output}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"stats_output"}) 23 37 60
516 # Write all stats for many iterations
517 86 ▶ _print_stats($fh, \%stats, $args) if $repeat > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $repeat > 1 1 22 23
518 86 _close_stats($fh, $args);
519 }
520 24 $args->{stats} = \%stats;
521 }
522  
523 21 ▶sub _warn_tracker {
Subroutine _warn_tracker: called CC=1 SCAR=0.1
524 17 my $warned = shift;
525 23 my $outer = $SIG{__WARN__};
526  
527 150 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.7
528 150 ▶ $$warned = 1 if join('', @_) =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
if join("", @_) =~ /\S/ 74 0 74
529 150 ▶ return $outer->(@_) if ref $outer eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $outer eq "CODE" 74 0 74
530 83 print STDERR @_;
531 16 };
532 }
533  
534 28 ▶sub _test_name {
Subroutine _test_name: called CC=2 SCAR=6.9
535 104 my $test = shift;
536 28 my $root = shift;
537  
538 28 ▶ $test =~ s/^\Q$root\E// if $root;
Branch: 1 branch
BranchTrueFalseTotal
if $root 30 80 110
539  
540 28 return $test;
541 }
542  
543 51 ▶sub _override {
Subroutine _override: called CC=2 SCAR=6.9
544 1 my $replace = shift;
545  
546 1 require Sub::Override;
547  
548 7 my $override = Sub::Override->new;
549 57 $override->replace($_, $replace->{$_}) for (keys %{$replace});
550  
551 36 return $override;
552 }
553  
554 42 ▶sub _stats_fh {
Subroutine _stats_fh: called CC=8 SCAR=20.8
555 46 my $args = shift;
556  
557 22 ▶ return unless $args->{stats_output};
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"stats_output"} 38 33 71
558  
559 27 my $fh;
560 6 ▶ if ($args->{stats_output} =~ /^-$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'stats_output'} =~ /^-$/) { } 6 27 33
561 3 $fh = *STDOUT
562 } else {
563 4 ▶ unless (-e $args->{stats_output}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $args->{"stats_output"}) 3 24 27
564 5 my @create = mkpath($args->{stats_output});
565 27 ▶ unless (scalar @create) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @create) 1 2 3
566 23 warn "Could not create ".$args->{stats_output};
567 28 return;
568 }
569 }
570 31 my $file = $args->{stats_output}."/".$args->{caller}."-"._timestamp().".txt";
571 31 ▶ open($fh, '>', $file) or die "Can't open > $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", $file or die "Can't open > ${file}: $!" 25 1 26
572 }
573 31 select($fh); $| = 1; select(STDOUT);
574  
575 31 $args->{total_time} = 0;
576 23 ▶ my $extra = $args->{extend_stats} ? ' TIMESTAMP' : '';
Branch: 1 branch
BranchTrueFalseTotal
$args->{'extend_stats'} ? : 1 30 31
577 23 ▶ print $fh "TIME PASS%$extra TEST\n" unless $args->{pass_only};
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"pass_only"} 6 25 31
578  
579 22 return $fh;
580 }
581  
582 35 ▶sub _close_stats {
Subroutine _close_stats: called CC=4 SCAR=13.9
583 22 my ($fh, $args) = @_;
584  
585 35 ▶ return unless $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless $fh 1 22 23
586  
587 printf $fh "TOTAL TIME: %.1f sec\n", $args->{total_time}
588 35 ▶ unless $args->{pass_only};
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"pass_only"} 6 16 22
589 34 ▶ close $fh unless $args->{stats_output} =~ /^-$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"stats_output"} =~ /^-$/ 16 6 22
590 }
591  
592 59 ▶sub _print_stats {
Subroutine _print_stats: called CC=7 SCAR=19.5
593 34 my ($fh, $stats, $args, $test) = @_;
594  
595 34 ▶ return unless $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless $fh 1 34 35
596  
597 4 ▶ my @tests = $test ? $test : keys %$stats;
Branch: 1 branch
BranchTrueFalseTotal
$test ? : 33 1 34
598 35 my $extra = '';
599  
600 24 foreach my $test (sort {$stats->{$b}->{time}<=>$stats->{$a}->{time}} @tests) {
601 14 ▶ if ($args->{pass_only}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"pass_only"}) 24 11 35
602 14 ▶ print $fh "$test\n" if $stats->{$test}->{pass_perc} > 99;
Branch: 1 branch
BranchTrueFalseTotal
if $stats->{$test}{"pass_perc"} > 99 22 2 24
603 14 next;
604 }
605 52 ▶ $extra = ' '.$stats->{$test}->{timestamp} if $args->{extend_stats};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"extend_stats"} 2 9 11
606 52 $args->{total_time} += $stats->{$test}->{time};
607 printf $fh "%.2f %d$extra $test\n",
608 100 $stats->{$test}->{time}, $stats->{$test}->{pass_perc};
609 }
610 }
611  
612 114 ▶sub _uniq {
Subroutine _uniq: called CC=1 SCAR=0.0
613 114 my %seen;
614 50 grep !$seen{$_}++, @_;
615 }
616  
617 56 ▶sub _timestamp {
Subroutine _timestamp: called CC=1 SCAR=0.0
618 72 my ($s, $m, $h, $D, $M, $Y) = localtime(time);
619 56 return sprintf "%04d%02d%02dT%02d%02d%02d", $Y+1900, $M+1, $D, $h, $m, $s;
620 }
621  
622 =head1 HELPER SCRIPTS
623  
624 =head2 agg (Test2::Aggregate harness wrapper)
625  
626 agg [options] <file/dir1 ...>
627  
628 Pass a list of Perl test files/directories and they will run aggregated via yath
629 (or prove if specified). It is not meant to be used for .t files that use Test2::Aggregate
630 themselves.
631  
632 It is useful either to speed up a test run for tests you know can be aggregated,
633 or to check whether specific tests can run successfully under Test2::Aggregate.
634  
635 Options:
636 --out <s>, -o <s> : Specify the test file to be created (tmp file by default).
637 --lists, -l : Use files specified as lists.
638 --prove, -p : Force prove (default is yath/Test2 if installed).
639 --verbose, -v : Verbose (passed to yath/prove)
640 --absolute, -a : Use absolute paths in generated files. Disabled with -r.
641 --include_regex <s> -ir <s> : Regex for test paths to include.
642 --exclude_regex <s> -er <s> : Regex for test paths to exclude.
643 --root <s> -r <s> : Define a custom root dir (default is current dir).
644 --include <s>, -I <s> : Library paths to include.
645 --test_warnings, -w : Fail tests on warnings.
646 --test_bundle <s>, -t : Test bundle (def: Test2::V0 or Test::More if -p). Can be comma-separated list.
647 --pass_output <s>, -po <s> : Output directory for list of 100% passing tests.
648 --reverse : Reverse the test order.
649 --shuffle : Shuffle the test order.
650 --sort : Run the tests alphabetically.
651 --stats_output <s>, -so <s> : Stats output directory (does not combine with pass_output).
652 --help -h : Show basic help and exit.
653  
654 =head2 aggit (Test2::Aggregate iterative aggregator)
655  
656 aggit [options] <file/dir1 ...>
657  
658 Runs tests through an aggregate test repeatedly. On each failed run, the active
659 test file is removed and the remaining set is tried again. Requires
660 L<Test2::Plugin::BailOnFail>. Startup failures and failures after all test files
661 have completed abort the command with a nonzero exit status instead of removing
662 tests. This is a coarse way to discover a starting list of tests that can be
663 aggregated together, not proof that each removed test is independently broken.
664  
665 C<--sort>, C<--shuffle>, and C<--reverse> are applied once during discovery.
666 The resulting order is preserved across retries and in the generated runner.
667 By default, list entries are relative to the generated runner's directory;
668 C<--absolute> writes absolute paths. C<--root> resolves inputs against a custom
669 directory. C<--exclude_regex> and C<--exclude_list> filter the discovered tests.
670  
671 C<aggit> passes C<--event_timeout SECONDS> (alias C<-et>, default 10) to
672 C<yath> as C<--et SECONDS>. This is an inactivity timeout, not a total runtime
673 limit; Harness normally defaults to 60 seconds. The timeout applies to the
674 generated aggregate runner, so C<# HARNESS-NO-TIMEOUT> comments in individual
675 aggregated files do not disable it. Under C<--prove>, or automatic fallback to
676 C<prove> when Harness is unavailable, this timeout is not provided and hung
677 tests require external supervision.
678  
679 For C<agg>, C<--pass_output> takes precedence over C<--stats_output> when both
680 are supplied.
681  
682 =head2 Common helper workflows
683  
684 Try known-safe tests through the default L<Test2::Harness> runner:
685  
686 agg t/unit t/lib
687  
688 Force C<prove> and L<Test::More> compatibility mode:
689  
690 agg --prove t/unit
691  
692 Generate a directory containing a list of tests that passed when aggregated:
693  
694 agg --root . --pass_output pass t
695  
696 C<--root .> makes the passing paths relative to the current project directory,
697 rather than the temporary aggregate runner's directory.
698  
699 Iteratively discover an aggregateable list and generated aggregate test:
700  
701 aggit --out aggregate-candidate t
702  
703 Run the generated aggregate test later (its list paths are runner-relative):
704  
705 yath test aggregate-candidate.t
706  
707 =head1 USAGE NOTES
708  
709 Not all tests can be modified to run under the aggregator, it is not intended
710 for tests that require an isolated environment, do overrides etc. For other tests
711 which can potentially run under the aggregator, sometimes very simple changes may be
712 needed like giving unique names to subs (or not warning for redefines, or trying the
713 package option), replacing things that complain, restoring the environment at
714 the end of the test etc.
715  
716 Unit tests are usually great for aggregating. You could use the hash that C<run_tests>
717 returns in a script that tries to add more tests automatically to an aggregate list
718 to see which added tests passed and keep them, dropping failures. See later in the
719 notes for a detailed example.
720  
721 Trying to aggregate too many tests into a single one can be counter-intuitive as
722 you would ideally want to parallelize your test suite (so a super-long aggregated
723 test continuing after the rest are done will slow down the suite). And in general
724 more tests will run aggregated if they are grouped so that tests that can't be
725 aggregated together are in different groups.
726  
727 You can call C<Test2::Aggregate::run_tests> multiple times in a test. Nested calls
728 are skipped unless the inner call enables C<recursion>. Loading
729 L<Test2::Plugin::BailOnFail> through C<bail_on_fail> or C<repeat E<lt> 0> affects
730 subsequent tests too: a later failure will also trigger a bail-out.
731  
732 =head2 Version 1.00 path compatibility
733  
734 Stats keys and warning labels are root-relative by default in 1.00. Set
735 C<absolute> if you need the previous full rooted paths in stats output.
736  
737 Relative test paths that do not start with C</>, C<.>, or C<./> are now executed
738 with a C<./> prefix so they keep working on perls where C<.> is not in C<@INC>.
739 Set C<no_dot> if you need the previous behaviour.
740  
741 Nested aggregate runs are skipped by default when C<$ENV{AGGREGATE_TESTS}> is
742 already set. Set C<recursion> only for suites where nested aggregate execution is
743 intentional.
744  
745 =head2 Test::More
746  
747 If you haven't switched to the L<Test2::Suite> you are generally advised to do so
748 for a number of reasons, compatibility with this module being only a very minor
749 one. If you are stuck with a L<Test::More> suite, L<Test2::Aggregate> can still
750 probably help you more than the similarly-named C<Test::Aggregate...> modules.
751  
752 Although the module tries to load C<Test2> with minimal imports to not interfere,
753 it is generally better to do C<use Test::More;> in your aggregating test (i.e.
754 alongside with C<use Test2::Aggregate>).
755  
756 =head2 Test::Builder
757  
758 To avoid warnings, if you are importing L<Test::Builder> in multiple aggregated
759 tests, you will want to import first on the aggregating test.
760 It might look like this:
761  
762 use Test::Builder;
763 use Test2::V0;
764 use Test2::Aggregate;
765  
766 Test2::Aggregate::run_tests( ... );
767  
768 =head2 BEGIN / END Blocks
769  
770 C<BEGIN> blocks run as each test file is compiled. C<END> blocks are deferred
771 until the aggregate process exits, not the end of each individual test file.
772 Cleanup needed between files must therefore happen before the file returns.
773 Global overrides can affect later tests. One example is a
774 C<*CORE::GLOBAL::exit> override to test scripts that can call C<exit()>.
775 A solution is to use something like L<Test::Trap>:
776  
777 BEGIN {
778 unless ($Test::Trap::VERSION) { # Avoid warnings for multiple loads in aggregation
779 require Test::Trap;
780 Test::Trap->import();
781 }
782 }
783  
784 =head2 Test::Class
785  
786 L<Test::Class> is sort of an aggregator itself. You make your tests into modules
787 and then load them on the same C<.t> file, so ideally you will not end up with many
788 C<.t> files that would require further aggregation. If you do, due to the L<Test::Class>
789 implementation specifics, those C<.t> files won't run under L<Test2::Aggregate>.
790  
791 =head2 $0 variable
792  
793 Remember the C<$0> variable is the aggregate runner, not the test file.
794  
795 =head2 Mocks, CORE::GLOBAL::* Overrides
796  
797 Always prefer mocks (Test2::Mock) instead of global built-ins where possible for
798 aggregated tests. Remember to clear mocks at the end of test.
799  
800 =head2 $ENV{AGGREGATE_TESTS}
801  
802 The environment variable C<AGGREGATE_TESTS> will be set while the tests are running
803 for your convenience. Example usage is making a test you know cannot run under the
804 aggregator check and croak if it was run under it, or a module that can only be loaded
805 once, so you load it on the aggregated test file and then use something like this in
806 the individual test files:
807  
808 eval 'use My::Module' unless $ENV{AGGREGATE_TESTS};
809  
810 If you have a custom test bundle, you could use the variable to do things like
811 disable warnings on redefines only for tests that run aggregated:
812  
813 use Import::Into;
814  
815 sub import {
816 ...
817 'warnings'->unimport::out_of($package, 'redefine')
818 if $ENV{AGGREGATE_TESTS};
819 }
820  
821 Another idea is to make the test die when it is run under the aggregator, if, at
822 design time, you know it is not supposed to run aggregated.
823  
824 =head2 Example aggregating strategy
825  
826 There are many approaches you could do to use C<Test2::Aggregate> with an existing
827 test suite, usually involving an iterative process of trying to run several tests
828 aggregated, seeing if you can fix the failing ones, otherwise you remove them from
829 the aggregation etc.
830  
831 This process can be done with the help of the C<agg> script. For example, to try
832 all tests under C<t/> aggregated and a list of passing tests put under the C<pass>
833 directory you would do:
834  
835 > agg --root . --pass_output pass t
836  
837 (which will use C<yath> & L<Test2::V0>, you can do
838 C<agg --prove --root . --pass_output pass t> for C<prove> & L<Test::More>)
839  
840 If the run completes, thanks to C<--pass_output> you have a "starting point"
841 i.e. a .txt list that can run under the aggregator with the C<lists> option:
842  
843 Test2::Aggregate::run_tests(
844 lists => ['pass/name_of_file.txt']
845 );
846  
847 If the run does not complete (e.g. signal 11 on some test), try fewer tests by
848 choosing just a subdirectory. If that's not possible, you'll probably have to go
849 to the more manual method of getting a full list of your tests
850 (C<find t -name '*.t' E<gt> all.lst>) then trying to run parts of it, again with
851 the C<lists> option.
852  
853 After you have a starting point, you can try see if there is an obvious reason some
854 tests fail and address it to add them back to the pass list. You can even try adding
855 back some of the failed tests that were not among the first to fail - test failures
856 can sometimes be cascading, so some might be passing if added back, or have small
857 issues you can address.
858  
859 Try adding C<test_warnings =E<gt> 1> to C<run_tests> to fix warnings as well, unless
860 it is common for your tests to have C<STDERR> output.
861  
862 In the end, you will end up with part of your tests aggregated in (multiple if you
863 want to run them in parallel) list files, with the rest of your tests to be run
864 non-aggregated.
865  
866 You don't actually have to move and separate aggregated/non-aggregated files when
867 using lists, you can still have your entire suite run the aggregated tests once and
868 not repeat them along with the other, non-aggregated tests, by taking advantage of
869 the C<--exclude-list> option of the C<Test2::Harness>.
870  
871 Hopefully your tests can run in parallel (C<prove/yath -j>), in which case you
872 would split your aggregated tests into multiple lists to have them run in parallel.
873 Here is an example of a wrapper around C<yath>, to easily handle multiple lists:
874  
875 BEGIN {
876 my @args = ();
877 foreach (@ARGV) {
878 if (/--exclude-lists=(\S+)/) {
879 my $all = 't/aggregate/aggregated.tests';
880 `awk '{print "t/"\$0}' $1 > $all`;
881 push @args, "--exclude-list=$all";
882 } else { push @args, $_ if $_; }
883 }
884 push @args, qw(-P...) # Preload module list (useful for non-aggregated tests)
885 unless grep {/--cover/} @args;
886 @ARGV = @args;
887 }
888 exec ('yath', @ARGV);
889  
890 You would call it with something like C<--exclude-lists=t/aggregate/*.lst>, and
891 the tests listed will be excluded (you will have them running aggregated through
892 their own C<.t> files using L<Test2::Aggregate>).
893  
894 =head1 WINDOWS SUPPORT
895  
896 Only filesystems with the C</> separator are supported, simply because the author
897 does not expect Windows users (many test suites don't work under StrawberryPerl
898 etc). However, if you want Windows filesystems to be supported, it should be simple
899 enough as long as you are willing to help with testing - just ask.
900  
901 =head1 DEVELOPMENT AND RELEASES
902  
903 C<README.md> is generated from this module's POD using L<Pod::Markdown>.
904 Install author dependencies, then run:
905  
906 perl Makefile.PL
907 make readme
908 AUTHOR_TESTING=1 prove -Ilib xt/author xt/integration
909 make disttest
910  
911 C<make readme> refreshes the README. C<make distdir> (also used by C<make dist>
912 and C<make disttest>) refreshes it automatically before copying distribution
913 files. These author targets require L<Pod::Markdown>, but normal installation
914 and C<make test> do not. The README author test detects stale generated content;
915 review and commit README changes alongside the POD. Set the release date in
916 C<Changes> when preparing the final release.
917  
918 =head1 AUTHOR
919  
920 Dimitrios Kechagias, L<https://metacpan.org/author/DKECHAG>
921
922 =head1 BUGS
923  
924 Please report any bugs or feature requests to C<bug-test2-aggregate at rt.cpan.org>,
925 or through the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test2-Aggregate>.
926 I will be notified, and then you'll automatically be notified of progress on your
927 bug as I make changes. You could also submit issues or even pull requests to the
928 github repo (see below).
929  
930 =head1 GIT
931  
932 L<https://github.com/SpareRoom/Test2-Aggregate>
933
934 =head1 COPYRIGHT & LICENSE
935  
936 Copyright (C) 2019, SpareRoom.com
937  
938 This program is free software; you can redistribute
939 it and/or modify it under the same terms as Perl itself.
940  
941 =cut
942  
943 26 1;
↑ Summary blib/lib/Test2/Aggregate/Helper.pm »