blib/lib/Test2/Formatter/TAP.pm

filter: Statementstmt 98.3% 240 / 244 Branchbran 91.5% 130 / 142 Conditioncond 81.7% 103 / 126 MC/DCmcdc 61.6% 45 / 73 Subroutinesub 100% 26 / 26 Podpod 12.5% 2 / 16 totaltotal 87.0% 546 / 627 CC 119 SCAR 27.0
CC
119
Cov
92%
assert_tap
32.6
write
17.2
print_optimal_pass
16.2
CRAP 14.9
« blib/lib/Test2/API/Instance.pm ↑ Summary blib/lib/Test2/Tools/ClassicCompare.pm »
1 package Test2::Formatter::TAP;
2 455 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 455 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 455 our $VERSION = '1.302226';
6  
7 455 ▶use Test2::Util qw/clone_io/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 455 ▶use Test2::Util::HashBase qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
10 no_numbers handles _encoding _last_fh
11 -made_assertion
12 455 };
13  
14 sub OUT_STD() { 0 }
15 sub OUT_ERR() { 1 }
16  
17 455 ▶BEGIN { require Test2::Formatter; our @ISA = qw(Test2::Formatter) }
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 455 my $supports_tables;
20 6 ▶sub supports_tables {
Subroutine supports_tables: called CC=5 SCAR=16.3
Pod undocumented
21 6 ▶ if (!defined $supports_tables) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $supports_tables) 2 4 6
22 2 local $SIG{__DIE__} = 'DEFAULT';
23 2 local $@;
24 $supports_tables
25 = ($INC{'Term/Table.pm'} && $INC{'Term/Table/Util.pm'})
26 2 ▶ || eval { require Term::Table; require Term::Table::Util; 1 }
Condition62%5/8
$INC{'Term/Table.pm'} && $INC{'Term/Table/Util.pm'} || eval { do { require Term::Table; require Term::Table::Util; 1 } } || 0
l!l
20
$INC{"Term/Table.pm"} and $INC{"Term/Table/Util.pm"} or eval { do { require Term::Table; require Term::Table::Util; 1 } }
l!l&&r!l&&!r
110
$INC{"Term/Table.pm"} and $INC{"Term/Table/Util.pm"}
!ll&&!rl&&r
101
MC/DC0%0/3
$INC{'Term/Table.pm'} && $INC{'Term/Table/Util.pm'} || eval { do { require Term::Table; require Term::Table::Util; 1 } } || 0
$INC{"Term/Table.pm"} $INC{"Term/Table/Util.pm"} eval { do { require Term::Table; require Term::Table::Util; 1 } }
Truth table40%2/5
A and B or C
A= $INC{"Term/Table.pm"}B= $INC{"Term/Table/Util.pm"}C= eval { do { require Term::Table; require Term::Table::Util; 1 } }
ABCresult
11X1
0X11
1011
0X00
1000
27 || 0;
28 }
29 6 return $supports_tables;
30 }
31  
32 2062 ▶sub _autoflush {
Subroutine _autoflush: called CC=1 SCAR=0.0
33 2062 my($fh) = pop;
34 2062 my $old_fh = select $fh;
35 2062 $| = 1;
36 2062 select $old_fh;
37 }
38  
39 455 _autoflush(\*STDOUT);
40 455 _autoflush(\*STDERR);
41  
42 416 ▶sub hide_buffered { 1 }
Subroutine hide_buffered: called CC=1 SCAR=0.0
Pod undocumented
43  
44 588 ▶sub init {
Subroutine init: called CC=3 SCAR=11.0
Pod undocumented
45 588 my $self = shift;
46  
47 588 ▶ $self->{+HANDLES} ||= $self->_open_handles;
Condition66%2/3
$self->{"handles"} ||= $self->_open_handles
l!l&&r!l&&!r
125760
MC/DC0%0/2
$self->{"handles"} ||= $self->_open_handles
$self->{"handles"} $self->_open_handles
Truth table66%2/3
A ||= B
A= $self->{"handles"}B= $self->_open_handles
ABresult
1X1
011
000
48 588 ▶ if(my $enc = delete $self->{encoding}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $enc = delete $self->{"encoding"}) 1 587 588
49 1 $self->encoding($enc);
50 }
51 }
52  
53 576 ▶sub _open_handles {
Subroutine _open_handles: called CC=1 SCAR=0.0
54 576 my $self = shift;
55  
56 576 require Test2::API;
57 576 my $out = clone_io(Test2::API::test2_stdout());
58 576 my $err = clone_io(Test2::API::test2_stderr());
59  
60 576 _autoflush($out);
61 576 _autoflush($err);
62  
63 576 return [$out, $err];
64 }
65  
66 168 ▶sub encoding {
Subroutine encoding: called CC=6 SCAR=18.3
Pod documented
67 168 my $self = shift;
68  
69 168 ▶ if ("$]" >= 5.007003 and @_) {
Branch: 1 branch
BranchTrueFalseTotal
if ("$]" >= "5.007003" and @_) 167 1 168
Condition66%2/3
"$]" >= "5.007003" and @_
!ll&&!rl&&r
01167
MC/DC50%1/2
"$]" >= "5.007003" and @_
"$]" >= "5.007003" @_
Truth table66%2/3
A and B
A= "$]" >= "5.007003"B= @_
ABresult
0X0
100
111
70 167 my ($enc) = @_;
71 167 my $handles = $self->{+HANDLES};
72  
73 # https://rt.perl.org/Public/Bug/Display.html?id=31923
74 # If utf8 is requested we use ':utf8' instead of ':encoding(utf8)' in
75 # order to avoid the thread segfault.
76 167 ▶ if ($enc =~ m/^utf-?8$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enc =~ /^utf-?8$/i) { } 167 0 167
77 167 binmode($_, ":utf8") for @$handles;
78 }
79 else {
80 0 binmode($_, ":encoding($enc)") for @$handles;
81 }
82 167 $self->{+_ENCODING} = $enc;
83 }
84  
85 168 return $self->{+_ENCODING};
86 }
87  
88 455 ▶if ($^C) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^C) 1 454 455
89 455 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
90 1 ▶ *write = sub {};
Subroutine __ANON__: called CC=1 SCAR=0.0
91 }
92 6413 ▶sub write {
Subroutine write: called CC=17 SCAR=28.5
Pod documented
93 6413 my ($self, $e, $num, $f) = @_;
94  
95 # The most common case, a pass event with no amnesty and a normal name.
96 6413 ▶ return if $self->print_optimal_pass($e, $num);
Branch: 1 branch
BranchTrueFalseTotal
if $self->print_optimal_pass($e, $num) 3511 2902 6413
97  
98 2902 ▶ $f ||= $e->facet_data;
Condition66%2/3
$f ||= $e->facet_data
l!l&&r!l&&!r
2860420
MC/DC0%0/2
$f ||= $e->facet_data
$f $e->facet_data
Truth table66%2/3
A ||= B
A= $fB= $e->facet_data
ABresult
1X1
011
000
99  
100 2902 ▶ $self->encoding($f->{control}->{encoding}) if $f->{control}->{encoding};
Branch: 1 branch
BranchTrueFalseTotal
if $f->{"control"}{"encoding"} 0 2902 2902
101  
102 2902 ▶ my @tap = $self->event_tap($f, $num) or return;
Branch: 1 branch
BranchTrueFalseTotal
my(@tap) = $self->event_tap($f, $num) or return 2540 362 2902
103  
104 2540 ▶ $self->{+MADE_ASSERTION} = 1 if $f->{assert};
Branch: 1 branch
BranchTrueFalseTotal
if $f->{"assert"} 954 1586 2540
105  
106 2540 ▶ my $nesting = $f->{trace}->{nested} || 0;
Condition100%2/2
$f->{'trace'}{'nested'} || 0
l!l
5102030
MC/DC100%1/1
$f->{'trace'}{'nested'} || 0
$f->{'trace'}{'nested'}
Truth table100%2/2
A
A= $f->{'trace'}{'nested'}
Aresult
11
00
107 2540 my $handles = $self->{+HANDLES};
108 2540 my $indent = ' ' x $nesting;
109  
110 # Local is expensive! Only do it if we really need to.
111 2540 ▶ local($\, $,) = (undef, '') if $\ || $,;
Branch: 1 branch
BranchTrueFalseTotal
if $\ or $, 2 2538 2540
Condition66%2/3
$\ or $,
l!l&&r!l&&!r
202538
MC/DC50%1/2
$\ or $,
$\ $,
Truth table66%2/3
A or B
A= $\B= $,
ABresult
1X1
011
000
112 2540 for my $set (@tap) {
113 455 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
114 5782 my ($hid, $msg) = @$set;
115 5782 ▶ next unless $msg;
Branch: 1 branch
BranchTrueFalseTotal
unless $msg 0 5782 5782
116 5782 ▶ my $io = $handles->[$hid] or next;
Branch: 1 branch
BranchTrueFalseTotal
my $io = $handles->[$hid] or next 5782 0 5782
117  
118 print $io "\n"
119 if $ENV{HARNESS_ACTIVE}
120 && $hid == OUT_ERR
121 5782 ▶ && $self->{+_LAST_FH} != $io
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"HARNESS_ACTIVE"} and $hid == 1 and $self->{"_last_fh"} != $io and $msg =~ /^#\s*Failed( \(TODO\))? test / 30 5752 5782
Condition100%9/9
$ENV{"HARNESS_ACTIVE"} and $hid == 1 and $self->{"_last_fh"} != $io and $msg =~ /^#\s*Failed( \(TODO\))? test /
!ll&&!rl&&r
57302230
$ENV{"HARNESS_ACTIVE"} and $hid == 1 and $self->{"_last_fh"} != $io
!ll&&!rl&&r
57042652
$ENV{"HARNESS_ACTIVE"} and $hid == 1
!ll&&!rl&&r
1377432778
MC/DC100%4/4
$ENV{"HARNESS_ACTIVE"} and $hid == 1 and $self->{"_last_fh"} != $io and $msg =~ /^#\s*Failed( \(TODO\))? test /
$ENV{"HARNESS_ACTIVE"} $hid == 1 $self->{"_last_fh"} != $io $msg =~ /^#\s*Failed( \(TODO\))? test /
Truth table100%5/5
A and B and C and D
A= $ENV{"HARNESS_ACTIVE"}B= $hid == 1C= $self->{"_last_fh"} != $ioD= $msg =~ /^#\s*Failed( \(TODO\))? test /
ABCDresult
0XXX0
10XX0
110X0
11100
11111
122 && $msg =~ m/^#\s*Failed( \(TODO\))? test /;
123  
124 5782 ▶ $msg =~ s/^/$indent/mg if $nesting;
Branch: 1 branch
BranchTrueFalseTotal
if $nesting 511 5271 5782
125 5782 print $io $msg;
126 5782 $self->{+_LAST_FH} = $io;
127 }
128 }
129  
130 6425 ▶sub print_optimal_pass {
Subroutine print_optimal_pass: called CC=16 SCAR=27.8
Pod undocumented
131 6425 my ($self, $e, $num) = @_;
132  
133 6425 my $type = ref($e);
134  
135 # Only optimal if this is a Pass or a passing Ok
136 6425 ▶ return unless $type eq 'Test2::Event::Pass' || ($type eq 'Test2::Event::Ok' && $e->{pass});
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "Test2::Event::Pass" or $type eq "Test2::Event::Ok" and $e->{"pass"} 2866 3559 6425
Condition100%6/6
$type eq "Test2::Event::Pass" or $type eq "Test2::Event::Ok" and $e->{"pass"}
l!l&&r!l&&!r
122723322866
$type eq "Test2::Event::Ok" and $e->{"pass"}
!ll&&!rl&&r
24354312332
MC/DC100%3/3
$type eq "Test2::Event::Pass" or $type eq "Test2::Event::Ok" and $e->{"pass"}
$type eq "Test2::Event::Pass" $type eq "Test2::Event::Ok" $e->{"pass"}
Truth table100%4/4
A or B and C
A= $type eq "Test2::Event::Pass"B= $type eq "Test2::Event::Ok"C= $e->{"pass"}
ABCresult
1XX1
0111
00X0
0100
137  
138 # Amnesty requires further processing (todo is a form of amnesty)
139 3559 ▶ return if ($e->{amnesty} && @{$e->{amnesty}}) || defined($e->{todo});
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"amnesty"} and @{$e->{"amnesty"};} or defined $e->{"todo"} 27 3532 3559
Condition83%5/6
$e->{"amnesty"} and @{$e->{"amnesty"};} or defined $e->{"todo"}
l!l&&r!l&&!r
14133532
$e->{"amnesty"} and @{$e->{"amnesty"};}
!ll&&!rl&&r
3545014
MC/DC66%2/3
$e->{"amnesty"} and @{$e->{"amnesty"};} or defined $e->{"todo"}
$e->{"amnesty"} @{$e->{"amnesty"};} defined $e->{"todo"}
Truth table60%3/5
A and B or C
A= $e->{"amnesty"}B= @{$e->{"amnesty"};}C= defined $e->{"todo"}
ABCresult
11X1
0X11
1011
0X00
1000
140  
141 # A name with a newline or hash symbol needs extra processing
142 3532 ▶ return if defined($e->{name}) && (-1 != index($e->{name}, "\n") || -1 != index($e->{name}, '#'));
Branch: 1 branch
BranchTrueFalseTotal
if defined $e->{"name"} and index($e->{"name"}, "\n") != -1 || index($e->{"name"}, "#") != -1 15 3517 3532
Condition100%6/6
defined $e->{"name"} and index($e->{"name"}, "\n") != -1 || index($e->{"name"}, "#") != -1
!ll&&!rl&&r
392312515
index($e->{"name"}, "\n") != -1 or index($e->{"name"}, "#") != -1
l!l&&r!l&&!r
1323125
MC/DC100%3/3
defined $e->{"name"} and index($e->{"name"}, "\n") != -1 || index($e->{"name"}, "#") != -1
defined $e->{"name"} index($e->{"name"}, "\n") != -1 index($e->{"name"}, "#") != -1
Truth table100%4/4
A and B or C
A= defined $e->{"name"}B= index($e->{"name"}, "\n") != -1C= index($e->{"name"}, "#") != -1
ABCresult
0XX0
1000
11X1
1011
143  
144 3517 my $ok = 'ok';
145 3517 ▶ $ok .= " $num" if $num && !$self->{+NO_NUMBERS};
Branch: 1 branch
BranchTrueFalseTotal
if $num and not $self->{"no_numbers"} 3516 1 3517
Condition66%2/3
$num and not $self->{"no_numbers"}
!ll&&!rl&&r
013516
MC/DC50%1/2
$num and not $self->{"no_numbers"}
$num not $self->{"no_numbers"}
Truth table66%2/3
A and not(B)
A= $numB= not $self->{"no_numbers"}
ABresult
0X0
100
111
146 3517 ▶ $ok .= defined($e->{name}) ? " - $e->{name}\n" : "\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $e->{'name'} ? : 3125 392 3517
147  
148 3517 ▶ if (my $nesting = $e->{trace}->{nested}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $nesting = $e->{"trace"}{"nested"}) 91 3426 3517
149 91 my $indent = ' ' x $nesting;
150 91 $ok = "$indent$ok";
151 }
152  
153 3517 my $io = $self->{+HANDLES}->[OUT_STD];
154  
155 3517 ▶ local($\, $,) = (undef, '') if $\ || $,;
Branch: 1 branch
BranchTrueFalseTotal
if $\ or $, 0 3517 3517
Condition33%1/3
$\ or $,
l!l&&r!l&&!r
003517
MC/DC0%0/2
$\ or $,
$\ $,
Truth table33%1/3
A or B
A= $\B= $,
ABresult
1X1
011
000
156 3517 print $io $ok;
157 3517 $self->{+_LAST_FH} = $io;
158  
159 3517 return 1;
160 }
161  
162 5850 ▶sub event_tap {
Subroutine event_tap: called CC=14 SCAR=26.4
Pod undocumented
163 5850 my ($self, $f, $num) = @_;
164  
165 5850 my @tap;
166  
167 # If this IS the first event the plan should come first
168 # (plan must be before or after assertions, not in the middle)
169 5850 ▶ push @tap => $self->plan_tap($f) if $f->{plan} && !$self->{+MADE_ASSERTION};
Branch: 1 branch
BranchTrueFalseTotal
if $f->{"plan"} and not $self->{"made_assertion"} 477 5373 5850
Condition100%3/3
$f->{"plan"} and not $self->{"made_assertion"}
!ll&&!rl&&r
4874499477
MC/DC100%2/2
$f->{"plan"} and not $self->{"made_assertion"}
$f->{"plan"} not $self->{"made_assertion"}
Truth table100%3/3
A and not(B)
A= $f->{"plan"}B= not $self->{"made_assertion"}
ABresult
0X0
100
111
170  
171 # The assertion is most important, if present.
172 5850 ▶ if ($f->{assert}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f->{"assert"}) 3323 2527 5850
173 3323 push @tap => $self->assert_tap($f, $num);
174 3323 ▶ push @tap => $self->debug_tap($f, $num) unless $f->{assert}->{no_debug} || $f->{assert}->{pass};
Branch: 1 branch
BranchTrueFalseTotal
unless $f->{"assert"}{"no_debug"} or $f->{"assert"}{"pass"} 18 3305 3323
Condition100%3/3
$f->{"assert"}{"no_debug"} or $f->{"assert"}{"pass"}
l!l&&r!l&&!r
261369218
MC/DC100%2/2
$f->{"assert"}{"no_debug"} or $f->{"assert"}{"pass"}
$f->{"assert"}{"no_debug"} $f->{"assert"}{"pass"}
Truth table100%3/3
A or B
A= $f->{"assert"}{"no_debug"}B= $f->{"assert"}{"pass"}
ABresult
1X1
011
000
175 }
176  
177 # Almost as important as an assertion
178 5850 ▶ push @tap => $self->error_tap($f) if $f->{errors};
Branch: 1 branch
BranchTrueFalseTotal
if $f->{"errors"} 4 5846 5850
179  
180 # Now lets see the diagnostics messages
181 5850 ▶ push @tap => $self->info_tap($f) if $f->{info};
Branch: 1 branch
BranchTrueFalseTotal
if $f->{"info"} 1040 4810 5850
182  
183 # If this IS NOT the first event the plan should come last
184 # (plan must be before or after assertions, not in the middle)
185 5850 ▶ push @tap => $self->plan_tap($f) if $self->{+MADE_ASSERTION} && $f->{plan};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"made_assertion"} and $f->{"plan"} 499 5351 5850
Condition100%3/3
$self->{"made_assertion"} and $f->{"plan"}
!ll&&!rl&&r
14203931499
MC/DC100%2/2
$self->{"made_assertion"} and $f->{"plan"}
$self->{"made_assertion"} $f->{"plan"}
Truth table100%3/3
A and B
A= $self->{"made_assertion"}B= $f->{"plan"}
ABresult
0X0
100
111
186  
187 # Bail out
188 5850 ▶ push @tap => $self->halt_tap($f) if $f->{control}->{halt};
Branch: 1 branch
BranchTrueFalseTotal
if $f->{"control"}{"halt"} 7 5843 5850
189  
190 5850 ▶ return @tap if @tap;
Branch: 1 branch
BranchTrueFalseTotal
if @tap 5333 517 5850
191 517 ▶ return @tap if $f->{control}->{halt};
Branch: 1 branch
BranchTrueFalseTotal
if $f->{"control"}{"halt"} 2 515 517
192 515 ▶ return @tap if grep { $f->{$_} } qw/assert plan info errors/;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$f->{$_};} "assert", "plan", "info", "errors" 4 511 515
193  
194 # Use the summary as a fallback if nothing else is usable.
195 511 return $self->summary_tap($f, $num);
196 }
197  
198 5 ▶sub error_tap {
Subroutine error_tap: called CC=4 SCAR=14.1
Pod undocumented
199 5 my $self = shift;
200 5 my ($f) = @_;
201  
202 0 ▶ my $IO = ($f->{amnesty} && @{$f->{amnesty}}) ? OUT_STD : OUT_ERR;
Branch: 1 branch
BranchTrueFalseTotal
$f->{'amnesty'} && @{$f->{'amnesty'};} ? : 0 5 5
Condition33%1/3
$f->{"amnesty"} and @{$f->{"amnesty"};}
!ll&&!rl&&r
500
MC/DC0%0/2
$f->{"amnesty"} and @{$f->{"amnesty"};}
$f->{"amnesty"} @{$f->{"amnesty"};}
Truth table33%1/3
A and B
A= $f->{"amnesty"}B= @{$f->{"amnesty"};}
ABresult
0X0
100
111
203  
204 return map {
205 7 my $details = $_->{details};
206  
207 7 my $msg;
208 7 ▶ if (ref($details)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $details) { } 1 6 7
209 1 require Data::Dumper;
210 1 my $dumper = Data::Dumper->new([$details])->Indent(2)->Terse(1)->Pad('# ')->Useqq(1)->Sortkeys(1);
211 1 chomp($msg = $dumper->Dump);
212 }
213 else {
214 6 chomp($msg = $details);
215 6 $msg =~ s/^/# /;
216 6 $msg =~ s/\n/\n# /g;
217 }
218  
219 7 [$IO, "$msg\n"];
220 5 } @{$f->{errors}};
221 }
222  
223 979 ▶sub plan_tap {
Subroutine plan_tap: called CC=5 SCAR=16.1
Pod undocumented
224 979 my $self = shift;
225 979 my ($f) = @_;
226 979 ▶ my $plan = $f->{plan} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $plan = $f->{"plan"} or return 978 1 979
227  
228 978 ▶ return if $plan->{none};
Branch: 1 branch
BranchTrueFalseTotal
if $plan->{"none"} 2 976 978
229  
230 976 ▶ if ($plan->{skip}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($plan->{"skip"}) 44 932 976
231 44 ▶ my $reason = $plan->{details} or return [OUT_STD, "1..0 # SKIP\n"];
Branch: 1 branch
BranchTrueFalseTotal
my $reason = $plan->{"details"} or return [0, "1..0 # SKIP\n"] 41 3 44
232 41 chomp($reason);
233 41 return [OUT_STD, '1..0 # SKIP ' . $reason . "\n"];
234 }
235  
236 932 return [OUT_STD, "1.." . $plan->{count} . "\n"];
237 }
238  
239 2713 ▶sub no_subtest_space { 0 }
Subroutine no_subtest_space: called CC=1 SCAR=0.0
Pod undocumented
240 3363 ▶sub assert_tap {
Subroutine assert_tap: called CC=32 SCAR=34.8
Pod undocumented
241 3363 my $self = shift;
242 3363 my ($f, $num) = @_;
243  
244 3363 ▶ my $assert = $f->{assert} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $assert = $f->{"assert"} or return 3363 0 3363
245 3363 my $pass = $assert->{pass};
246 3363 my $name = $assert->{details};
247  
248 3363 ▶ my $ok = $pass ? 'ok' : 'not ok';
Branch: 1 branch
BranchTrueFalseTotal
$pass ? : 2829 534 3363
249 3363 ▶ $ok .= " $num" if $num && !$self->{+NO_NUMBERS};
Branch: 1 branch
BranchTrueFalseTotal
if $num and not $self->{"no_numbers"} 3324 39 3363
Condition66%2/3
$num and not $self->{"no_numbers"}
!ll&&!rl&&r
0393324
MC/DC50%1/2
$num and not $self->{"no_numbers"}
$num not $self->{"no_numbers"}
Truth table66%2/3
A and not(B)
A= $numB= not $self->{"no_numbers"}
ABresult
0X0
100
111
250  
251 # The regex form is ~250ms, the index form is ~50ms
252 3363 my @extra;
253 3363 ▶ defined($name) && (
Branch: 1 branch
BranchTrueFalseTotal
defined $name and index($name, "\n") != -1 && (($name, @extra) = split(/\n\r?/, $name, -1)), (index($name, "#") != -1 || substr($name, -1) eq "\\") && ($name =~ s/\\/\\\\/g, $name =~ s/#/\\#/g) 3290 73 3363
Condition77%7/9
index($name, "\n") != -1 and ($name, @extra) = split(/\n\r?/, $name, -1)
!ll&&!rl&&r
3265250
index($name, "#") != -1 || substr($name, -1) eq "\\" and $name =~ s/\\/\\\\/g, $name =~ s/#/\\#/g
!ll&&!rl&&r
328181
index($name, "#") != -1 or substr($name, -1) eq "\\"
l!l&&r!l&&!r
903281
MC/DC0%0/2
index($name, "\n") != -1 and ($name, @extra) = split(/\n\r?/, $name, -1)
index($name, "\n") != -1 ($name, @extra) = split(/\n\r?/, $name, -1)
MC/DC0%0/3
index($name, "#") != -1 || substr($name, -1) eq "\\" and $name =~ s/\\/\\\\/g, $name =~ s/#/\\#/g
index($name, "#") != -1 substr($name, -1) eq "\\" $name =~ s/\\/\\\\/g, $name =~ s/#/\\#/g
Truth table66%2/3
A and B
A= index($name, "\n") != -1B= ($name, @extra) = split(/\n\r?/, $name, -1)
ABresult
0X0
100
111
Truth table0%0/5
A or B and C
A= index($name, "#") != -1B= substr($name, -1) eq "\\"C= $name =~ s/\\/\\\\/g, $name =~ s/#/\\#/g
ABCresult
00X0
1X00
0100
1X11
0111
254 (index($name, "\n") != -1 && (($name, @extra) = split(/\n\r?/, $name, -1))),
255 ((index($name, "#" ) != -1 || substr($name, -1) eq '\\') && (($name =~ s|\\|\\\\|g), ($name =~ s|#|\\#|g)))
256 );
257  
258 3363 ▶ my $extra_space = @extra ? ' ' x (length($ok) + 2) : '';
Branch: 1 branch
BranchTrueFalseTotal
@extra ? : 25 3338 3363
259 3363 my $extra_indent = '';
260  
261 3363 my ($directives, $reason, $is_skip);
262 3363 ▶ if ($f->{amnesty}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f->{"amnesty"}) 352 3011 3363
263 352 my %directives;
264  
265 352 for my $am (@{$f->{amnesty}}) {
266 365 ▶ next if $am->{inherited};
Branch: 1 branch
BranchTrueFalseTotal
if $am->{"inherited"} 1 364 365
267 364 ▶ my $tag = $am->{tag} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $tag = $am->{"tag"} or next 364 0 364
268 364 ▶ $is_skip = 1 if $tag eq 'skip';
Branch: 1 branch
BranchTrueFalseTotal
if $tag eq "skip" 48 316 364
269  
270 364 ▶ $directives{$tag} ||= $am->{details};
Condition100%3/3
$directives{$tag} ||= $am->{"details"}
l!l&&r!l&&!r
3254107
MC/DC100%2/2
$directives{$tag} ||= $am->{"details"}
$directives{$tag} $am->{"details"}
Truth table100%3/3
A ||= B
A= $directives{$tag}B= $am->{"details"}
ABresult
1X1
011
000
271 }
272  
273 352 my %seen;
274  
275 # Sort so that TODO comes before skip even on systems where lc sorts
276 # before uc, as other code depends on that ordering.
277 352 my @order = grep { !$seen{$_}++ } sort { lc $b cmp lc $a } keys %directives;
278  
279 352 $directives = ' # ' . join ' & ' => @order;
280  
281 352 for my $tag ('skip', @order) {
282 659 ▶ next unless defined($directives{$tag}) && length($directives{$tag});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $directives{$tag} and length $directives{$tag} 365 294 659
Condition100%3/3
defined $directives{$tag} and length $directives{$tag}
!ll&&!rl&&r
31649294
MC/DC100%2/2
defined $directives{$tag} and length $directives{$tag}
defined $directives{$tag} length $directives{$tag}
Truth table100%3/3
A and B
A= defined $directives{$tag}B= length $directives{$tag}
ABresult
0X0
100
111
283 294 $reason = $directives{$tag};
284 294 last;
285 }
286 }
287  
288 3363 ▶ $ok .= " - $name" if defined $name && !($is_skip && !$name);
Branch: 1 branch
BranchTrueFalseTotal
if defined $name and not $is_skip && !$name 3275 88 3363
Condition100%6/6
defined $name and not $is_skip && !$name
!ll&&!rl&&r
73153275
$is_skip && !$name
!ll&&!rl&&r
32542115
MC/DC100%3/3
defined $name and not $is_skip && !$name
defined $name $is_skip !$name
Truth table100%4/4
A and not(B && not(C))
A= defined $nameB= $is_skipC= !$name
ABCresult
0XX0
1110
10X1
1101
289  
290 3363 my @subtap;
291 3363 ▶ if ($f->{parent} && $f->{parent}->{buffered}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f->{"parent"} and $f->{"parent"}{"buffered"}) 410 2953 3363
Condition100%3/3
$f->{"parent"} and $f->{"parent"}{"buffered"}
!ll&&!rl&&r
286489410
MC/DC100%2/2
$f->{"parent"} and $f->{"parent"}{"buffered"}
$f->{"parent"} $f->{"parent"}{"buffered"}
Truth table100%3/3
A and B
A= $f->{"parent"}B= $f->{"parent"}{"buffered"}
ABresult
0X0
100
111
292 410 $ok .= ' {';
293  
294 # In a verbose harness we indent the extra since they will appear
295 # inside the subtest braces. This helps readability. In a non-verbose
296 # harness we do not do this because it is less readable.
297 410 ▶ if ($ENV{HARNESS_IS_VERBOSE} || !$ENV{HARNESS_ACTIVE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"HARNESS_IS_VERBOSE"} or not $ENV{"HARNESS_ACTIVE"}) 0 410 410
Condition33%1/3
$ENV{"HARNESS_IS_VERBOSE"} or not $ENV{"HARNESS_ACTIVE"}
l!l&&r!l&&!r
00410
MC/DC0%0/2
$ENV{"HARNESS_IS_VERBOSE"} or not $ENV{"HARNESS_ACTIVE"}
$ENV{"HARNESS_IS_VERBOSE"} not $ENV{"HARNESS_ACTIVE"}
Truth table33%1/3
A or not(B)
A= $ENV{"HARNESS_IS_VERBOSE"}B= not $ENV{"HARNESS_ACTIVE"}
ABresult
1X1
011
000
298 0 $extra_indent = " ";
299 0 $extra_space = ' ';
300 }
301  
302 # Render the sub-events, we use our own counter for these.
303 410 my $count = 0;
304 @subtap = map {
305 2939 my $f2 = $_;
306  
307 # Bump the count for any event that should bump it.
308 2939 ▶ $count++ if $f2->{assert};
Branch: 1 branch
BranchTrueFalseTotal
if $f2->{"assert"} 2365 574 2939
309  
310 # This indents all output lines generated for the sub-events.
311 # index 0 is the filehandle, index 1 is the message we want to indent.
312 2939 map { $_->[1] =~ s/^(.*\S.*)$/ $1/mg; $_ } $self->event_tap($f2, $count);
313 410 } @{$f->{parent}->{children}};
314  
315 410 push @subtap => [OUT_STD, "}\n"];
316 }
317  
318 3363 ▶ if ($directives) {
Branch: 1 branch
BranchTrueFalseTotal
if ($directives) 352 3011 3363
319 352 ▶ $directives = ' # TODO & SKIP' if $directives eq ' # TODO & skip';
Branch: 1 branch
BranchTrueFalseTotal
if $directives eq " # TODO & skip" 10 342 352
320 352 $ok .= $directives;
321 352 ▶ $ok .= " $reason" if defined($reason);
Branch: 1 branch
BranchTrueFalseTotal
if defined $reason 294 58 352
322 }
323  
324 3363 ▶ $extra_space = ' ' if $self->no_subtest_space;
Branch: 1 branch
BranchTrueFalseTotal
if $self->no_subtest_space 651 2712 3363
325  
326 3363 my @out = ([OUT_STD, "$ok\n"]);
327 3363 ▶ push @out => map {[OUT_STD, "${extra_indent}#${extra_space}$_\n"]} @extra if @extra;
Branch: 1 branch
BranchTrueFalseTotal
if @extra 25 3338 3363
328 3363 push @out => @subtap;
329  
330 3363 return @out;
331 }
332  
333 24 ▶sub debug_tap {
Subroutine debug_tap: called CC=10 SCAR=23.1
Pod undocumented
334 24 my ($self, $f, $num) = @_;
335  
336 # Figure out the debug info, this is typically the file name and line
337 # number, but can also be a custom message. If no trace object is provided
338 # then we have nothing useful to display.
339 24 my $name = $f->{assert}->{details};
340 24 my $trace = $f->{trace};
341  
342 24 my $debug = "[No trace info available]";
343 24 ▶ if ($trace->{details}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($trace->{'details'}) { } 1 23 24
elsif ($trace->{'frame'}) { } 20 3 23
344 1 $debug = $trace->{details};
345 }
346 elsif ($trace->{frame}) {
347 20 my ($pkg, $file, $line) = @{$trace->{frame}};
348 20 ▶ $debug = "at $file line $line." if $file && $line;
Branch: 1 branch
BranchTrueFalseTotal
if $file and $line 20 0 20
Condition33%1/3
$file and $line
!ll&&!rl&&r
0020
MC/DC0%0/2
$file and $line
$file $line
Truth table33%1/3
A and B
A= $fileB= $line
ABresult
0X0
100
111
349 }
350  
351 24 ▶ my $amnesty = $f->{amnesty} && @{$f->{amnesty}}
Branch: 1 branch
BranchTrueFalseTotal
$f->{'amnesty'} && @{$f->{'amnesty'};} ? : 4 20 24
Condition100%3/3
$f->{"amnesty"} and @{$f->{"amnesty"};}
!ll&&!rl&&r
1914
MC/DC100%2/2
$f->{"amnesty"} and @{$f->{"amnesty"};}
$f->{"amnesty"} @{$f->{"amnesty"};}
Truth table100%3/3
A and B
A= $f->{"amnesty"}B= @{$f->{"amnesty"};}
ABresult
0X0
100
111
352 ? ' (with amnesty)'
353 : '';
354  
355 # Create the initial diagnostics. If the test has a name we put the debug
356 # info on a second line, this behavior is inherited from Test::Builder.
357 24 ▶ my $msg = defined($name)
Branch: 1 branch
BranchTrueFalseTotal
defined $name ? : 20 4 24
358 ? qq[# Failed test${amnesty} '$name'\n# $debug\n]
359 : qq[# Failed test${amnesty} $debug\n];
360  
361 24 ▶ my $IO = $f->{amnesty} && @{$f->{amnesty}} ? OUT_STD : OUT_ERR;
Branch: 1 branch
BranchTrueFalseTotal
$f->{'amnesty'} && @{$f->{'amnesty'};} ? : 4 20 24
Condition100%3/3
$f->{"amnesty"} and @{$f->{"amnesty"};}
!ll&&!rl&&r
1914
MC/DC100%2/2
$f->{"amnesty"} and @{$f->{"amnesty"};}
$f->{"amnesty"} @{$f->{"amnesty"};}
Truth table100%3/3
A and B
A= $f->{"amnesty"}B= @{$f->{"amnesty"};}
ABresult
0X0
100
111
362  
363 24 return [$IO, $msg];
364 }
365  
366 13 ▶sub halt_tap {
Subroutine halt_tap: called CC=5 SCAR=16.1
Pod undocumented
367 13 my ($self, $f) = @_;
368  
369 13 ▶ return if $f->{trace}->{nested} && !$f->{trace}->{buffered};
Branch: 1 branch
BranchTrueFalseTotal
if $f->{"trace"}{"nested"} and not $f->{"trace"}{"buffered"} 3 10 13
Condition100%3/3
$f->{"trace"}{"nested"} and not $f->{"trace"}{"buffered"}
!ll&&!rl&&r
913
MC/DC100%2/2
$f->{"trace"}{"nested"} and not $f->{"trace"}{"buffered"}
$f->{"trace"}{"nested"} not $f->{"trace"}{"buffered"}
Truth table100%3/3
A and not(B)
A= $f->{"trace"}{"nested"}B= not $f->{"trace"}{"buffered"}
ABresult
0X0
100
111
370 10 my $details = $f->{control}->{details};
371  
372 10 ▶ return [OUT_STD, "Bail out!\n"] unless defined($details) && length($details);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $details and length $details 3 7 10
Condition100%3/3
defined $details and length $details
!ll&&!rl&&r
217
MC/DC100%2/2
defined $details and length $details
defined $details length $details
Truth table100%3/3
A and B
A= defined $detailsB= length $details
ABresult
0X0
100
111
373 7 return [OUT_STD, "Bail out! $details\n"];
374 }
375  
376 1041 ▶sub info_tap {
Subroutine info_tap: called CC=9 SCAR=22.1
Pod undocumented
377 1041 my ($self, $f) = @_;
378  
379 return map {
380 1051 my $details = $_->{details};
381 1051 my $table = $_->{table};
382  
383 1051 ▶ my $IO = $_->{debug} && !($f->{amnesty} && @{$f->{amnesty}}) ? OUT_ERR : OUT_STD;
Branch: 1 branch
BranchTrueFalseTotal
$_->{'debug'} && !($f->{'amnesty'} && @{$f->{'amnesty'};}) ? : 332 719 1051
Condition83%5/6
$_->{"debug"} and not $f->{"amnesty"} && @{$f->{"amnesty"};}
!ll&&!rl&&r
7181332
$f->{'amnesty'} && @{$f->{'amnesty'};}
!ll&&!rl&&r
33201
MC/DC66%2/3
$_->{"debug"} and not $f->{"amnesty"} && @{$f->{"amnesty"};}
$_->{"debug"} $f->{'amnesty'} @{$f->{'amnesty'};}
Truth table75%3/4
A and not(B && C)
A= $_->{"debug"}B= $f->{'amnesty'}C= @{$f->{'amnesty'};}
ABCresult
0XX0
1110
10X1
1101
384  
385 1051 my $msg;
386 1051 ▶ if ($table && $self->supports_tables) {
Branch: 2 branches
BranchTrueFalseTotal
if ($table and $self->supports_tables) { } 5 1046 1051
elsif (ref $details) { } 2 1044 1046
Condition100%3/3
$table and $self->supports_tables
!ll&&!rl&&r
104425
MC/DC100%2/2
$table and $self->supports_tables
$table $self->supports_tables
Truth table100%3/3
A and B
A= $tableB= $self->supports_tables
ABresult
0X0
100
111
387 5 my $size = $self->calc_table_size($f);
388  
389 43 $msg = join "\n" => map { "# $_" } Term::Table->new(
390 header => $table->{header},
391 rows => $table->{rows},
392 collapse => $table->{collapse},
393 no_collapse => $table->{no_collapse},
394 5 sanitize => 1,
395 mark_tail => 1,
396 max_width => $size,
397 )->render();
398  
399 $msg .= "\n(If this table is too small, you can use the TABLE_TERM_SIZE=### env var to set a larger size, detected size is '$size')\n"
400 if $size <= 80
401 5 ▶ && !$ENV{TABLE_TERM_SIZE};
Branch: 1 branch
BranchTrueFalseTotal
if $size <= 80 and not $ENV{"TABLE_TERM_SIZE"} 0 5 5
Condition33%1/3
$size <= 80 and not $ENV{"TABLE_TERM_SIZE"}
!ll&&!rl&&r
050
MC/DC0%0/2
$size <= 80 and not $ENV{"TABLE_TERM_SIZE"}
$size <= 80 not $ENV{"TABLE_TERM_SIZE"}
Truth table33%1/3
A and not(B)
A= $size <= 80B= not $ENV{"TABLE_TERM_SIZE"}
ABresult
0X0
100
111
402 }
403 elsif (ref($details)) {
404 2 require Data::Dumper;
405 2 my $dumper = Data::Dumper->new([$details])->Indent(2)->Terse(1)->Pad('# ')->Useqq(1)->Sortkeys(1);
406 2 chomp($msg = $dumper->Dump);
407 }
408 else {
409 1044 chomp($msg = $details);
410 1044 $msg =~ s/^/# /;
411 1044 $msg =~ s/\n/\n# /g;
412 }
413  
414 1051 [$IO, "$msg\n"];
415 1041 } @{$f->{info}};
416 }
417  
418 514 ▶sub summary_tap {
Subroutine summary_tap: called CC=3 SCAR=11.0
Pod undocumented
419 514 my ($self, $f, $num) = @_;
420  
421 514 ▶ return if $f->{about}->{no_display};
Branch: 1 branch
BranchTrueFalseTotal
if $f->{"about"}{"no_display"} 155 359 514
422  
423 359 ▶ my $summary = $f->{about}->{details} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $summary = $f->{"about"}{"details"} or return 2 357 359
424 2 chomp($summary);
425 2 $summary =~ s/^/# /smg;
426  
427 2 return [OUT_STD, "$summary\n"];
428 }
429  
430 5 ▶sub calc_table_size {
Subroutine calc_table_size: called CC=3 SCAR=11.0
Pod undocumented
431 5 my $self = shift;
432 5 my ($f) = @_;
433  
434 5 my $term = Term::Table::Util::term_size();
435 5 ▶ my $nesting = 2 + (($f->{trace}->{nested} || 0) * 4); # 4 spaces per level, also '# ' prefix
Condition100%2/2
$f->{'trace'}{'nested'} || 0
l!l
32
MC/DC100%1/1
$f->{'trace'}{'nested'} || 0
$f->{'trace'}{'nested'}
Truth table100%2/2
A
A= $f->{'trace'}{'nested'}
Aresult
11
00
436 5 my $total = $term - $nesting;
437  
438 # Sane minimum width, any smaller and we are asking for pain
439 5 ▶ return 50 if $total < 50;
Branch: 1 branch
BranchTrueFalseTotal
if $total < 50 0 5 5
440  
441 5 return $total;
442 }
443  
444 455 1;
445  
446 __END__
« blib/lib/Test2/API/Instance.pm ↑ Summary blib/lib/Test2/Tools/ClassicCompare.pm »