Run/Obj/CanonFailedObj.pm

filter: Statementstmt 90.3% 75 / 83 Branchbran 57.1% 8 / 14 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 88.0% 22 / 25 Podpod 100% 10 / 10 totaltotal 87.5% 120 / 137 CC 10 SCAR 8.8
CC
10
Cov
86%
_add_actual_skipped
6.0
_calc_skipped_percent
6.0
_get_canon_ranges
5.0
CRAP 2.4
« Run/Class/Hierarchy.pm ↑ Summary Run/Straps/StrapsTotalsObj.pm »
1 package Test::Run::Obj::CanonFailedObj;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # TODO
7 # Refactor the hell out of this module.
8  
9 =head1 NAME
10  
11 Test::Run::Obj::CanonFailedObj - the failed tests canon object.
12  
13 =head1 METHODS
14  
15 =cut
16  
17 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 4 extends('Test::Run::Base::Struct');
20  
21 4 ▶use MRO::Compat;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 4 ▶use vars qw(@fields);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 4 has 'failed' => (is => "rw", isa => "ArrayRef");
26 has '_more_results' => (is => "rw", isa => "ArrayRef",
27 24 ▶ lazy => 1, default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
28 4 );
29  
30 sub _get_more_results
31 12 ▶{
Subroutine _get_more_results: called CC=1 SCAR=0.0
32 12 my $self = shift;
33  
34 12 return $self->_more_results();
35 }
36  
37 =head2 $self->add_result($result)
38  
39 Pushes $result to the result() slot.
40  
41 =cut
42  
43 sub add_result
44 48 ▶{
Subroutine add_result: called CC=1 SCAR=0.0
Pod documented
45 48 my $self = shift;
46 48 push @{$self->_more_results()}, @_;
47 }
48  
49 =head2 $self->get_ser_results()
50  
51 Returns the serialized results.
52  
53 =cut
54  
55 sub get_ser_results
56 12 ▶{
Subroutine get_ser_results: called CC=1 SCAR=0.0
Pod documented
57 12 my $self = shift;
58 12 return join("", @{$self->result()});
59 }
60  
61 =head2 $self->add_Failed($test)
62  
63 Add a failed test $test to the diagnostics.
64  
65 =cut
66  
67 sub _add_Failed_summary
68 24 ▶{
Subroutine _add_Failed_summary: called CC=1 SCAR=0.0
69 24 my ($self, $test) = @_;
70  
71 24 $self->add_result(
72 sprintf(
73 "\tFailed %s/%s tests, ",
74 $self->failed_num(),
75 $test->max()
76 )
77 );
78 }
79  
80 sub _add_Failed_percent_okay
81 24 ▶{
Subroutine _add_Failed_percent_okay: called CC=1 SCAR=0.0
82 24 my ($self, $test) = @_;
83  
84 24 $self->add_result(
85 $self->_calc_Failed_percent_okay($test)
86 );
87 }
88  
89 sub _calc_Failed_percent_okay
90 24 ▶{
Subroutine _calc_Failed_percent_okay: called CC=2 SCAR=7.2
91 24 my ($self, $test) = @_;
92  
93 return
94 24 ▶ $test->max()
Branch: 1 branch
BranchTrueFalseTotal
$test->max ? : 24 0 24
95 ? sprintf("%.2f%% okay", 100*(1-$self->failed_num()/$test->max()))
96 : "?% okay"
97 ;
98 }
99  
100 sub add_Failed
101 24 ▶{
Subroutine add_Failed: called CC=1 SCAR=0.0
Pod documented
102 24 my ($self, $test) = @_;
103  
104 24 my $max = $test->max();
105 24 my $failed_num = $self->failed_num();
106  
107 24 $self->_add_Failed_summary($test);
108 24 $self->_add_Failed_percent_okay($test);
109 }
110  
111 =head2 $self->add_skipped($test)
112  
113 Add a skipped test.
114  
115 =cut
116  
117 sub add_skipped
118 24 ▶{
Subroutine add_skipped: called CC=2 SCAR=8.1
Pod documented
119 24 my ($self, $test) = @_;
120  
121 24 ▶ if ($test->skipped())
Branch: 1 branch
BranchTrueFalseTotal
if ($test->skipped) 0 24 24
122 {
123 0 $self->_add_actual_skipped($test);
124 }
125 }
126  
127 sub _add_actual_skipped
128 0 ▶{
Subroutine _add_actual_skipped: not called CC=2 SCAR=17.9
129 0 my ($self, $test) = @_;
130  
131 0 ▶ my $tests_string = (($test->skipped() > 1) ? "tests" : "test");
Branch: 1 branch
BranchTrueFalseTotal
$test->skipped > 1 ? : 0 0 0
132  
133 0 $self->add_result(
134 sprintf(
135 " (less %s skipped %s: %s okay, %s%%)",
136 $test->skipped(),
137 $tests_string,
138 $self->_calc_skipped_percent($test),
139 )
140 );
141 }
142  
143 sub _calc_skipped_percent
144 0 ▶{
Subroutine _calc_skipped_percent: not called CC=2 SCAR=17.9
145 0 my ($self, $test) = @_;
146  
147 return
148 0 ▶ $test->max()
Branch: 1 branch
BranchTrueFalseTotal
$test->max ? : 0 0 0
149 ? sprintf("%.2f", 100*($self->good($test)/$test->max()))
150 : "?"
151 ;
152 }
153  
154 =head2 $self->good()
155  
156 Returns the number of good (non failing or skipped) tests.
157  
158 =cut
159  
160 sub good
161 0 ▶{
Subroutine good: not called CC=1 SCAR=6.9
Pod documented
162 0 my ($self, $test) = @_;
163  
164 0 return $test->max() - $self->failed_num() - $test->skipped();
165 }
166  
167 =head2 $self->add_Failed_and_skipped($test)
168  
169 Adds a test as both failed and skipped.
170  
171 =cut
172  
173 sub add_Failed_and_skipped
174 24 ▶{
Subroutine add_Failed_and_skipped: called CC=1 SCAR=0.0
Pod documented
175 24 my ($self, $t) = @_;
176  
177 24 $self->add_Failed($t);
178 24 $self->add_skipped($t);
179  
180 24 return;
181 }
182  
183 =head2 $self->canon_list()
184  
185 Returns the the failed tests as a list of ranges.
186  
187 =cut
188  
189 sub canon_list
190 24 ▶{
Subroutine canon_list: called CC=2 SCAR=6.9
Pod documented
191 24 my $self = shift;
192  
193 24 return (@{$self->failed()} == 1)
194 24 ▶ ? [ @{$self->failed()} ]
Branch: 1 branch
BranchTrueFalseTotal
@{$self->failed;} == 1 ? : 10 14 24
195 : $self->_get_canon_ranges()
196 ;
197 }
198  
199 sub _get_canon_ranges
200 14 ▶{
Subroutine _get_canon_ranges: called CC=5 SCAR=16.1
201 14 my $self = shift;
202  
203 14 my @failed = @{$self->failed()};
204  
205 # Assign the first number in the range.
206 14 my $min = shift(@failed);
207  
208 14 my $last = $min;
209  
210 14 my @ranges;
211  
212 14 foreach my $number (@failed, $failed[-1]) # Don't forget the last one
213 {
214 200024 ▶ if (($number > $last+1) || ($number == $last))
Branch: 1 branch
BranchTrueFalseTotal
if ($number > $last + 1 or $number == $last) { } 24 200000 200024
Condition100%3/3
$number > $last + 1 or $number == $last
l!l&&r!l&&!r
1014200000
MC/DC100%2/2
$number > $last + 1 or $number == $last
$number > $last + 1 $number == $last
Truth table100%3/3
A or B
A= $number > $last + 1B= $number == $last
ABresult
1X1
011
000
215 {
216 24 ▶ push @ranges, +($min == $last) ? $min : "$min-$last";
Branch: 1 branch
BranchTrueFalseTotal
$min == $last ? : 20 4 24
217 24 $min = $last = $number;
218 }
219 else
220 {
221 200000 $last = $number;
222 }
223 }
224  
225 14 return \@ranges;
226 }
227  
228 =head2 my $string = $self->canon()
229  
230 Returns the canon as a space-delimited string.
231  
232 =cut
233  
234 sub canon
235 12 ▶{
Subroutine canon: called CC=1 SCAR=0.0
Pod documented
236 12 my $self = shift;
237  
238 12 return join(' ', @{$self->canon_list()});
239 }
240  
241  
242 sub _get_failed_string
243 12 ▶{
Subroutine _get_failed_string: called CC=1 SCAR=0.0
244 12 my $self = shift;
245  
246 12 my $canon = $self->canon_list;
247  
248 return
249 12 sprintf("FAILED %s %s",
250 $self->_list_pluralize("test", $canon),
251 join(", ", @$canon)
252 );
253 }
254  
255 sub _get_failed_string_line
256 12 ▶{
Subroutine _get_failed_string_line: called CC=1 SCAR=0.0
257 12 my $self = shift;
258  
259 12 return $self->_get_failed_string() . "\n";
260 }
261  
262 =head2 $self->result()
263  
264 The non-serialized result of the test.
265  
266 =cut
267  
268 sub result
269 12 ▶{
Subroutine result: called CC=1 SCAR=0.0
Pod documented
270 12 my $self = shift;
271  
272 12 return [ $self->_get_failed_string_line(), @{$self->_get_more_results()} ];
273 }
274  
275 =head2 $self->failed_num()
276  
277 Returns the number of failed tests.
278  
279 =cut
280  
281 sub failed_num
282 72 ▶{
Subroutine failed_num: called CC=1 SCAR=0.0
Pod documented
283 72 my $self = shift;
284  
285 72 return scalar(@{$self->failed()});
286 }
287  
288 =head2 $self->add_skipped($test)
289  
290 Add a skipped test.
291  
292 =cut
293  
294  
295 =head1 LICENSE
296  
297 This file is licensed under the MIT X11 License:
298  
299 http://www.opensource.org/licenses/mit-license.php
300  
301 =head1 AUTHOR
302  
303 Shlomi Fish, L<http://www.shlomifish.org/>
304  
305 =head1 SEE ALSO
306  
307 L<Test::Run::Obj>, L<Test::Run::Core>.
308  
309 =cut
310  
311 4 1;
« Run/Class/Hierarchy.pm ↑ Summary Run/Straps/StrapsTotalsObj.pm »