lib/TAP/Harness/ReportByDescription.pm

filter: Statementstmt 86.5% 71 / 82 Branchbran 50.0% 23 / 46 Conditioncond 40.0% 2 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 73.1% 106 / 145 CC 26 SCAR 29.6
CC
26
Cov
72%
_get_parser_args
39.6
_aggregate_parallel
7.0
_aggregate_single
6.6
CRAP 19.3
↑ Summary blib/lib/TAP/Harness/Archive/MultipleHarnesses.pm »
1 package TAP::Harness::ReportByDescription;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use base 'TAP::Harness';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 our $VERSION = '0.08';
6  
7 =head1 NAME
8  
9 TAP::Harness::ReportByDescription - Report TAP output by test file description rather than test file name
10  
11 =head1 SYNOPSIS
12  
13 use TAP::Harness::ReportByDescription;
14 my $harness = TAP::Harness::ReportByDescription->new();
15 $harness->aggregate_tests($aggregator, @tests);
16  
17 =head1 DESCRIPTION
18  
19 This package subclasses TAP::Harness for the purpose of enabling a user to
20 report the TAP output for a test file by a user-provided description rather
21 than by the name of the test file itself.
22  
23 Why would you want to do this? Three reasons come to mind.
24  
25 =over 4
26  
27 =item * One Master Summary Rather Than Summaries for Individual Subharnesses
28  
29 Suppose that you had a F<make> testing target that is in essence nothing more
30 than a sequential run of several smaller testing targets, each of which is a
31 separate invocation of a test harness.
32  
33 make fulltest : test_prep \
34 compilers \
35 src \
36 oo \
37 codingstd \
38 examples
39  
40 Other things being equal, you would get a B<Summary> at the end of each of the
41 five targets or subharnesses. Under some circumstances, you might prefer to
42 get a single master Summary at the end of the overall program.
43  
44 =item * Multiple Runs of Same Tests in Different Environments
45  
46 Suppose that you had a set of tests that you wanted to run several times, each
47 time in a slightly different environment. You could write a program which
48 executes multiple runs, writing a summary after each run and then modifying
49 the environment for the next run.
50  
51 perl t/harness --gc-debug --runcore=bounds
52 perl t/harness --gc-debug --runcore=fast
53 perl t/harness --gc-debug --run-pbc
54  
55 As the TAP output flowed by, you would see three instances of each test:
56  
57 t/pmc/arrayiterator.t ............................ ok
58 # ...
59 t/pmc/arrayiterator.t ............................ ok
60 # ...
61 t/pmc/arrayiterator.t ............................ ok
62  
63 ... but you would not be able to tell from the test file's report itself which
64 harness it was a part of. Under certain circumstances it would be nice to be
65 able to differentiate among the different runs:
66  
67 bounds__t/pmc/arrayiterator.t .................... ok
68 # ...
69 fast__t/pmc/arrayiterator.t ...................... ok
70 # ...
71 pbc__t/pmc/arrayiterator.t ....................... ok
72  
73 Here you're providing a B<description> of each run of each test which provides
74 an observer with more information.
75  
76 =item * Preparation of a Test Harness Archive
77  
78 The ability to provide a specific description for a different run of the same
79 test becomes crucial when preparing a test harness archive. Currently, CPAN
80 distribution Test::Harness::Archive stores the TAP for a particular test file
81 in a file with the name of the test file itself. If you do multiple runs of
82 the same file in different environments, a later run of a test will overwrite
83 the TAP file from an earlier run. You would therefore only be able to include
84 the TAP from the last subharness in an archive. That would impede you from
85 sharing the full results of testing via a smoke-test aggregator such as
86 Smolder.
87  
88 =back
89  
90 In short, we need (a) a way to run multiple harnesses as if they were one, (b)
91 run the same tests through multiple harnesses and be able to quickly identify
92 which harness we were running it through, and (c) store multiple versions of a
93 file's TAP output in a test harness archive.
94  
95 Need (a) can actually be fulfilled with existing TAP::Parser::Aggregator
96 functionality. Let's build on that to meet needs (b) and (c). To do that we
97 need one package to subclass TAP::Harness and one to subclass
98 TAP::Harness::Archive. TAP::Harness::ReportByDescription and
99 TAP::Harness::Archive::MultiplesHarnesses are these packages.
100  
101 =head1 METHODS
102  
103 =head2 C<new()>
104  
105 Inherited from TAP::Harness.
106  
107 =head2 C<aggregate_tests()>
108  
109 Replicated, along with methods called internally from this method, from
110 TAP::Harness. The only change occurs in an internal method
111 C<_get_parser_args()>, which now assigns the individual test's B<filename> to
112 one variable and a user-provided B<description> to a second variable.
113  
114 my $test_prog = $job->filename;
115 my $spool_prog = $job->description;
116  
117 It is the latter variable which will appear on the console and in a test
118 archive. Since this occurs within an internal method, the user need make no
119 change in how C<aggregate_tests()> is called.
120  
121 =cut
122  
123 16 ▶sub aggregate_tests {
Subroutine aggregate_tests: called CC=3 SCAR=11.0
Pod documented
124 16 my ( $self, $aggregate, @tests ) = @_;
125  
126 16 my $scheduler = $self->make_scheduler(@tests);
127  
128 # #12458
129 local $ENV{HARNESS_IS_VERBOSE} = 1
130 16 ▶ if $self->{formatter}->{verbosity} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"formatter"}{"verbosity"} > 0 0 16 16
131  
132 # Formatter gets only names.
133 16 $self->{formatter}->prepare( map { $_->description } $scheduler->get_all );
134  
135 16 ▶ if ( $self->{formatter}->{jobs} > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'formatter'}{'jobs'} > 1) { } 1 15 16
136 1 $self->_aggregate_parallel( $aggregate, $scheduler );
137 }
138 else {
139 15 $self->_aggregate_single( $aggregate, $scheduler );
140 }
141  
142 16 return;
143 }
144  
145 1 ▶sub _aggregate_parallel {
Subroutine _aggregate_parallel: called CC=7 SCAR=19.5
146 1 my ( $self, $aggregate, $scheduler ) = @_;
147  
148 1 my $jobs = $self->jobs;
149 1 my $mux = $self->_construct( $self->multiplexer_class );
150  
151 RESULT: {
152  
153 # Keep multiplexer topped up
154 1 FILL:
155 11 ▶ while ( $mux->parsers < $jobs ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mux->parsers < $jobs) 13 0 13
156 13 my $job = $scheduler->get_job;
157  
158 # If we hit a spinner stop filling and start running.
159 13 ▶ last FILL if !defined $job || $job->is_spinner;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $job or $job->is_spinner 11 2 13
Condition66%2/3
not defined $job or $job->is_spinner
l!l&&r!l&&!r
1102
MC/DC50%1/2
not defined $job or $job->is_spinner
not defined $job $job->is_spinner
Truth table66%2/3
not(A) or B
A= not defined $jobB= $job->is_spinner
ABresult
1X1
011
000
160  
161 2 my ( $parser, $session ) = $self->make_parser($job);
162 2 $mux->add( $parser, [ $session, $job ] );
163 }
164  
165 11 ▶ if ( my ( $parser, $stash, $result ) = $mux->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $mux->next) 10 1 11
166 10 my ( $session, $job ) = @$stash;
167 10 ▶ if ( defined $result ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $result) { } 8 2 10
168 8 $session->result($result);
169 8 ▶ $self->_bailout($result) if $result->is_bailout;
Branch: 1 branch
BranchTrueFalseTotal
if $result->is_bailout 0 8 8
170 }
171 else {
172  
173 # End of parser. Automatically removed from the mux.
174 2 $self->finish_parser( $parser, $session );
175 2 $self->_after_test( $aggregate, $job, $parser );
176 2 $job->finish;
177 }
178 10 redo RESULT;
179 }
180 }
181  
182 1 return;
183 }
184  
185 15 ▶sub _aggregate_single {
Subroutine _aggregate_single: called CC=6 SCAR=18.9
186 15 my ( $self, $aggregate, $scheduler ) = @_;
187  
188 JOB:
189 15 ▶ while ( my $job = $scheduler->get_job ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $job = $scheduler->get_job) 30 15 45
190 30 ▶ next JOB if $job->is_spinner;
Branch: 1 branch
BranchTrueFalseTotal
if $job->is_spinner 0 30 30
191  
192 30 my ( $parser, $session ) = $self->make_parser($job);
193  
194 30 ▶ while ( defined( my $result = $parser->next ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $result = $parser->next)) 120 30 150
195 120 $session->result($result);
196 120 ▶ if ( $result->is_bailout ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->is_bailout) 0 120 120
197  
198 # Keep reading until input is exhausted in the hope
199 # of allowing any pending diagnostics to show up.
200 0 ▶ 1 while $parser->next;
Branch: 1 branch
BranchTrueFalseTotal
$parser->next and do { '???' } 0 0 0
201 0 $self->_bailout($result);
202 }
203 }
204  
205 30 $self->finish_parser( $parser, $session );
206 30 $self->_after_test( $aggregate, $job, $parser );
207 30 $job->finish;
208 }
209  
210 15 return;
211 }
212  
213 32 ▶sub make_parser {
Subroutine make_parser: called CC=1 SCAR=0.0
Pod documented
214 32 my ( $self, $job ) = @_;
215  
216 32 my $args = $self->_get_parser_args($job);
217 32 $self->_make_callback( 'parser_args', $args, $job->as_array_ref );
218 32 my $parser = $self->_construct( $self->parser_class, $args );
219  
220 32 $self->_make_callback( 'made_parser', $parser, $job->as_array_ref );
221 32 my $session = $self->{formatter}->open_test( $job->description, $parser );
222  
223 32 return ( $parser, $session );
224 }
225  
226 32 ▶sub _get_parser_args {
Subroutine _get_parser_args: called CC=13 SCAR=36.8
227 32 my ( $self, $job ) = @_;
228 32 my $test_prog = $job->filename;
229 32 my $spool_prog = $job->description;
230 32 my %args = ();
231  
232 32 ▶ $args{sources} = $self->sources if $self->sources;
Branch: 1 branch
BranchTrueFalseTotal
if $self->sources 0 32 32
233  
234 32 my @switches;
235 32 ▶ @switches = $self->lib if $self->lib;
Branch: 1 branch
BranchTrueFalseTotal
if $self->lib 32 0 32
236 32 ▶ push @switches => $self->switches if $self->switches;
Branch: 1 branch
BranchTrueFalseTotal
if $self->switches 32 0 32
237 32 $args{switches} = \@switches;
238 32 $args{spool} = $self->_open_spool($spool_prog);
239 32 $args{merge} = $self->merge;
240 32 $args{ignore_exit} = $self->ignore_exit;
241 32 ▶ $args{version} = $self->version if $self->version;
Branch: 1 branch
BranchTrueFalseTotal
if $self->version 0 32 32
242  
243 32 ▶ if ( my $exec = $self->exec ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $exec = $self->exec) { } 0 32 32
244 $args{exec}
245 0 ▶ = ref $exec eq 'CODE'
Branch: 1 branch
BranchTrueFalseTotal
ref $exec eq 'CODE' ? : 0 0 0
246 ? $exec->( $self, $test_prog )
247 : [ @$exec, $test_prog ];
248 0 ▶ if ( not defined $args{exec} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $args{'exec'}) { } 0 0 0
elsif ((ref $args{'exec'} || '') ne 'ARRAY') { } 0 0 0
249 0 $args{source} = $test_prog;
250 }
251 ▶ elsif ( ( ref( $args{exec} ) || "" ) ne "ARRAY" ) {
Condition0%0/2
ref $args{'exec'} || ''
l!l
00
MC/DC0%0/1
ref $args{'exec'} || ''
ref $args{'exec'}
Truth table0%0/2
A
A= ref $args{'exec'}
Aresult
11
00
252 0 $args{source} = delete $args{exec};
253 }
254 }
255 else {
256 32 $args{source} = $test_prog;
257 }
258  
259 32 ▶ if ( defined( my $test_args = $self->test_args ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $test_args = $self->test_args)) 0 32 32
260  
261 0 ▶ if ( ref($test_args) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $test_args eq "HASH") 0 0 0
262  
263 # different args for each test
264 0 ▶ if ( exists( $test_args->{ $job->description } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$test_args{$job->description}) { } 0 0 0
265 0 $test_args = $test_args->{ $job->description };
266 }
267 else {
268 0 $self->_croak( "TAP::Harness Can't find test_args for "
269 . $job->description );
270 }
271 }
272  
273 0 $args{test_args} = $test_args;
274 }
275 32 return \%args;
276 }
277  
278 3 1;
279  
280 =head1 EXAMPLE
281  
282 See C<TAP::Harness::Archive::MultipleHarnesses::runtests()>.
283  
284 =head1 AUTHOR
285  
286 99% of the code in this module comes from TAP::Harness, written by Andy
287 Armstrong and generations of Perl QA hackers. Documentation and the one small
288 code tweak needed were written by James E Keenan.
289  
290 =head1 LICENSE
291  
292 This is free software and is released under the same terms as Perl itself.
293  
294 =cut
295  
296 # vim:ts=4:sw=4:et:sta
↑ Summary blib/lib/TAP/Harness/Archive/MultipleHarnesses.pm »