lib/Test2/Aggregate.pm

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