blib/lib/TAP/Formatter/Console/ParallelSession.pm

filter: Statementstmt 30.1% 28 / 93 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 46.6% 7 / 15 Podpod 100% 4 / 4 totaltotal 25.6% 39 / 152 CC 17 SCAR 32.5
CC
17
Cov
22%
_output_ruler
72.0
result
20.0
close_test
20.0
CRAP 25.7
« blib/lib/Test/Harness.pm ↑ Summary blib/lib/TAP/Harness.pm »
1 package TAP::Formatter::Console::ParallelSession;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use base 'TAP::Formatter::Console::Session';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use constant WIDTH => 72; # Because Eric says
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 my %shared;
14  
15 0 ▶sub _initialize {
Subroutine _initialize: not called CC=2 SCAR=17.9
16 0 my ( $self, $arg_for ) = @_;
17  
18 0 $self->SUPER::_initialize($arg_for);
19 0 my $formatter = $self->formatter;
20  
21 # Horrid bodge. This creates our shared context per harness. Maybe
22 # TAP::Harness should give us this?
23 0 ▶ my $context = $shared{$formatter} ||= $self->_create_shared_context;
Condition0%0/3
$shared{$formatter} ||= $self->_create_shared_context
l!l&&r!l&&!r
000
MC/DC0%0/2
$shared{$formatter} ||= $self->_create_shared_context
$shared{$formatter} $self->_create_shared_context
Truth table0%0/3
A ||= B
A= $shared{$formatter}B= $self->_create_shared_context
ABresult
1X1
011
000
24 0 push @{ $context->{active} }, $self;
25  
26 0 return $self;
27 }
28  
29 0 ▶sub _create_shared_context {
Subroutine _create_shared_context: not called CC=1 SCAR=6.9
30 0 my $self = shift;
31 return {
32 0 active => [],
33 tests => 0,
34 fails => 0,
35 };
36 }
37  
38 =head1 NAME
39  
40 TAP::Formatter::Console::ParallelSession - Harness output delegate for parallel console output
41  
42 =head1 VERSION
43  
44 Version 3.52
45  
46 =cut
47  
48 1 our $VERSION = '3.52';
49  
50 =head1 DESCRIPTION
51  
52 This provides console orientated output formatting for L<TAP::Harness>
53 when run with multiple L<TAP::Harness/jobs>.
54  
55 =head1 SYNOPSIS
56  
57 =cut
58  
59 =head1 METHODS
60  
61 =head2 Class Methods
62  
63 =head3 C<header>
64  
65 Output test preamble
66  
67 =cut
68  
69 0 ▶sub header {
Subroutine header: not called CC=1 SCAR=0.0
Pod documented
70 }
71  
72 0 ▶sub _clear_ruler {
Subroutine _clear_ruler: not called CC=1 SCAR=6.9
73 0 my $self = shift;
74 0 $self->formatter->_output( "\r" . ( ' ' x WIDTH ) . "\r" );
75 }
76  
77 1 my $now = 0;
78 1 my $start;
79  
80 1 my $trailer = '... )===';
81 1 my $chop_length = WIDTH - length $trailer;
82  
83 0 ▶sub _output_ruler {
Subroutine _output_ruler: not called CC=8 SCAR=42.8
84 0 my ( $self, $refresh ) = @_;
85 0 my $new_now = time;
86 0 ▶ return if $new_now == $now and !$refresh;
Branch: 1 branch
BranchTrueFalseTotal
if $new_now == $now and not $refresh 0 0 0
Condition0%0/3
$new_now == $now and not $refresh
!ll&&!rl&&r
000
MC/DC0%0/2
$new_now == $now and not $refresh
$new_now == $now not $refresh
Truth table0%0/3
A and not(B)
A= $new_now == $nowB= not $refresh
ABresult
0X0
100
111
87 0 $now = $new_now;
88 0 ▶ $start ||= $now;
Condition0%0/3
$start ||= $now
l!l&&r!l&&!r
000
MC/DC0%0/2
$start ||= $now
$start $now
Truth table0%0/3
A ||= B
A= $startB= $now
ABresult
1X1
011
000
89 0 my $formatter = $self->formatter;
90 0 ▶ return if $formatter->really_quiet;
Branch: 1 branch
BranchTrueFalseTotal
if $formatter->really_quiet 0 0 0
91  
92 0 my $context = $shared{$formatter};
93  
94 0 my $ruler = sprintf '===( %7d;%d ', $context->{tests}, $now - $start;
95  
96 0 for my $active ( @{ $context->{active} } ) {
97 0 my $parser = $active->parser;
98 0 my $tests = $parser->tests_run;
99 0 ▶ my $planned = $parser->tests_planned || '?';
Condition0%0/2
$parser->tests_planned || '?'
l!l
00
MC/DC0%0/1
$parser->tests_planned || '?'
$parser->tests_planned
Truth table0%0/2
A
A= $parser->tests_planned
Aresult
11
00
100  
101 0 $ruler .= sprintf '%' . length($planned) . "d/$planned ", $tests;
102 }
103 0 chop $ruler; # Remove a trailing space
104 0 $ruler .= ')===';
105  
106 0 ▶ if ( length $ruler > WIDTH ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $ruler > 72) { } 0 0 0
107 0 $ruler =~ s/(.{$chop_length}).*/$1$trailer/o;
108 }
109 else {
110 0 $ruler .= '=' x ( WIDTH - length($ruler) );
111 }
112 0 $formatter->_output("\r$ruler");
113 }
114  
115 =head3 C<result>
116  
117 Called by the harness for each line of TAP it receives .
118  
119 =cut
120  
121 0 ▶sub result {
Subroutine result: not called CC=4 SCAR=30.0
Pod documented
122 0 my ( $self, $result ) = @_;
123 0 my $formatter = $self->formatter;
124  
125 # my $really_quiet = $formatter->really_quiet;
126 # my $show_count = $self->_should_show_count;
127  
128 0 ▶ if ( $result->is_test ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($result->is_test) { } 0 0 0
elsif ($result->is_bailout) { } 0 0 0
129 0 my $context = $shared{$formatter};
130 0 $context->{tests}++;
131  
132 0 my $active = $context->{active};
133 0 ▶ if ( @$active == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$active == 1) 0 0 0
134  
135 # There is only one test, so use the serial output format.
136 0 return $self->SUPER::result($result);
137 }
138  
139 0 $self->_output_ruler( $self->parser->tests_run == 1 );
140 }
141 elsif ( $result->is_bailout ) {
142 0 $formatter->_failure_output(
143 "Bailout called. Further testing stopped: "
144 . $result->explanation
145 . "\n" );
146 }
147 }
148  
149 =head3 C<clear_for_close>
150  
151 =cut
152  
153 0 ▶sub clear_for_close {
Subroutine clear_for_close: not called CC=3 SCAR=24.8
Pod documented
154 0 my $self = shift;
155 0 my $formatter = $self->formatter;
156 0 ▶ return if $formatter->really_quiet;
Branch: 1 branch
BranchTrueFalseTotal
if $formatter->really_quiet 0 0 0
157 0 my $context = $shared{$formatter};
158 0 ▶ if ( @{ $context->{active} } == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$context->{'active'};} == 1) { } 0 0 0
159 0 $self->SUPER::clear_for_close;
160 }
161 else {
162 0 $self->_clear_ruler;
163 }
164 }
165  
166 =head3 C<close_test>
167  
168 =cut
169  
170 0 ▶sub close_test {
Subroutine close_test: not called CC=4 SCAR=30.0
Pod documented
171 0 my $self = shift;
172 0 my $name = $self->name;
173 0 my $parser = $self->parser;
174 0 my $formatter = $self->formatter;
175 0 my $context = $shared{$formatter};
176  
177 0 $self->SUPER::close_test;
178  
179 0 my $active = $context->{active};
180  
181 0 my @pos = grep { $active->[$_]->name eq $name } 0 .. $#$active;
182  
183 0 ▶ die "Can't find myself" unless @pos;
Branch: 1 branch
BranchTrueFalseTotal
unless @pos 0 0 0
184 0 splice @$active, $pos[0], 1;
185  
186 0 ▶ if ( @$active > 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@$active > 1) { } 0 0 0
elsif (@$active == 1) { } 0 0 0
187 0 $self->_output_ruler(1);
188 }
189 elsif ( @$active == 1 ) {
190  
191 # Print out "test/name.t ...."
192 0 $active->[0]->SUPER::header;
193 }
194 else {
195  
196 # $self->formatter->_output("\n");
197 0 delete $shared{$formatter};
198 }
199 }
200  
201 1 1;
« blib/lib/Test/Harness.pm ↑ Summary blib/lib/TAP/Harness.pm »