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