Skip to content

Commit 372fbb7

Browse files
committed
add POD and test
1 parent d5f9ea2 commit 372fbb7

File tree

3 files changed

+63
-31
lines changed

3 files changed

+63
-31
lines changed

agg

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ agg - Test2::Aggregate harness wrapper
66

77
=head1 DESCRIPTION
88

9-
Pass Perl test files/directories and they will run aggregated via yath or prove.
9+
Pass a list of Perl test files/directories and they will run aggregated via yath
10+
(or prove if specified).
1011

1112
It is useful either to speed up a test run for tests you know can be aggregated,
1213
or to check whether specific tests can pass under Test2::Aggregate.

lib/Test2/Aggregate.pm

+48-29
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ Test2::Aggregate - Aggregate tests for increased speed
2626
2727
=head1 VERSION
2828
29-
Version 0.17
29+
Version 0.18
3030
3131
=cut
3232

33-
our $VERSION = '0.17';
33+
our $VERSION = '0.18';
3434

3535
=head1 DESCRIPTION
3636
@@ -565,47 +565,66 @@ disable warnings on redefines only for tests that run aggregated:
565565
Another idea is to make the test die when it is run under the aggregator, if, at
566566
design time, you know it is not supposed to run aggregated.
567567
568+
=head2 agg helper script
569+
570+
agg [options] <file/dir ...>
571+
572+
Pass a list of Perl test files/directories and they will run aggregated via yath
573+
(or prove if specified).
574+
575+
Options:
576+
--out <s>, -o <s> : Specify the test file to be created (tmp file by default).
577+
--prove, -p : Force prove (default is yath if detected).
578+
--verbose, -v : Verbose (passed to yath/prove)
579+
--include <s>, -I <s> : Library paths to include.
580+
--test_warnings, -w : Fail tests on warnings.
581+
--test_bundle <s>, -t : Test bundle (default: Test2::V0). Can be comma-separated list.
582+
--pass_list <s>, -l <s> : Output directory for list of 100% passing tests.
583+
--stats_output <s>, -s <s> : Stats output directory (does not combine with pass_list).
584+
--help -h : Show basic help and exit.
585+
568586
=head2 Example aggregating strategy
569587
570588
There are many approaches you could do to use C<Test2::Aggregate> with an existing
571-
test suite, so for example you can start by making a list of the test files you
572-
are trying to aggregate:
589+
test suite, usually involving an iterative process of trying to run several tests
590+
aggregated, seeing if you can fix the failing ones, otherwise you remove them from
591+
the aggregation etc.
573592
574-
find t -name '*.t' > all.lst
593+
This process can be done with the help of the C<agg> script. For example, to try
594+
all tests under C<t/> aggregated and a list of passing tests put under the C<pass>
595+
directory you would do:
575596
576-
If you have a substantial test suite, perhaps try with a portion of it (a subdir?)
577-
instead of the entire suite. In any case, try running them aggregated like this:
597+
> agg -p pass t
578598
579-
use Test2::Aggregate;
580-
use Test2::V0; # Or Test::More;
599+
If the run completes, you have a "starting point" - i.e. a .txt list that can run
600+
under the aggregator with the C<lists> option:
581601
582-
my $stats = Test2::Aggregate::run_tests(
583-
lists => ['all.lst'],
602+
Test2::Aggregate::run_tests(
603+
lists => ['pass/name_of_file.txt']
584604
);
585605
586-
open OUT, ">pass.lst";
587-
foreach my $test (sort {$stats->{$a}->{test_no} <=> $stats->{$b}->{test_no}} keys %$stats) {
588-
print OUT "$test\n" if $stats->{$test}->{pass_perc};
589-
}
590-
close OUT;
591-
592-
done_testing();
606+
If the run does not complete, try fewer tests by choosing just a subdirectory. If
607+
that's not possible, you'll probably have to go to the more manual method of getting
608+
a full list of your tests (C<find t -name '*.t' E<gt> all.lst>) then trying to run
609+
parts of it, again with the C<lists> option.
593610
594-
Run the above with C<prove> or C<yath> in verbose mode, so that in case the run
595-
hangs (it can happen), you can see where it did so and edit C<all.lst> removing
596-
the offending test.
597-
598-
If the run completes, you have a "starting point" - i.e. a list that can run under
599-
the aggregator in C<pass.lst>.
600-
You can try adding back some of the failed tests - test failures can be cascading,
601-
so some might be passing if added back, or have small issues you can address.
611+
After you have a starting point, you can try see if there is an obvious reason some
612+
tests fail and address it to add them back to the pass list. You can even try adding
613+
back some of the failed tests that were not among the first to fail - test failures
614+
can sometimes be cascading, so some might be passing if added back, or have small
615+
issues you can address.
602616
603617
Try adding C<test_warnings =E<gt> 1> to C<run_tests> to fix warnings as well, unless
604618
it is common for your tests to have C<STDERR> output.
605619
606-
To have your entire suite run aggregated tests together once and not repeat them
607-
along with the other, non-aggregated, tests, it is a good idea to use the
608-
C<--exclude-list> option of the C<Test2::Harness>.
620+
In the end, you will end up with part of your tests aggregated in (multiple if you
621+
want to run them in parallel) list files, with the rest of your tests to be run
622+
non-aggregated.
623+
624+
You don't actually have to move and separate aggregated/non-aggregated files when
625+
using lists, you can still have your entire suite run the aggregated tests once and
626+
not repeat them along with the other, non-aggregated tests, by taking advantage of
627+
the C<--exclude-list> option of the C<Test2::Harness>.
609628
610629
Hopefully your tests can run in parallel (C<prove/yath -j>), in which case you
611630
would split your aggregated tests into multiple lists to have them run in parallel.

t/stats.t

+13-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ my $pattrn = 'stats.t.*txt';
99
my $tmpdir = File::Temp->newdir;
1010

1111
plan skip_all => "Cannot create temp directory" unless -e $tmpdir;
12-
plan(12);
12+
plan(15);
1313

1414
foreach my $extend (0 .. 1) {
1515
stdout_like(sub {
@@ -25,6 +25,18 @@ foreach my $extend (0 .. 1) {
2525
);
2626
}
2727

28+
stdout_like(sub {
29+
Test2::Aggregate::run_tests(
30+
dirs => ['xt/aggregate'],
31+
root => $root,
32+
stats_output => '-',
33+
pass_only => 1
34+
)
35+
},
36+
qr/^(?:\S*\n)+$/,
37+
"Valid stats output for pass_only"
38+
);
39+
2840
Test2::Aggregate::run_tests(
2941
dirs => ['xt/aggregate'],
3042
root => $root,

0 commit comments

Comments
 (0)