Run/Straps/StrapsTotalsObj.pm

filter: Statementstmt 96.4% 136 / 141 Branchbran 82.1% 23 / 28 Conditioncond 77.7% 21 / 27 MC/DCmcdc 50.0% 8 / 16 Subroutinesub 97.4% 38 / 39 Podpod 100% 7 / 7 totaltotal 90.3% 233 / 258 CC 23 SCAR 7.6
CC
23
Cov
92%
_get_skip_reason
4.5
_calc_all_process_status
4.1
_is_all_tests_passed
4.0
CRAP 2.1
« Run/Obj/CanonFailedObj.pm ↑ Summary Run/Obj/IntOrUnknown.pm »
1 package Test::Run::Straps::StrapsTotalsObj;
2  
3 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 Test::Run::Straps::StrapsTotalsObj - an object representing the totals of the
9 straps class.
10  
11 =head1 FIELDS
12  
13 =cut
14  
15 15 ▶use Test::Run::Straps::StrapsDetailsObj;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 15 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 15 extends('Test::Run::Straps::Base');
20  
21 15 has 'bonus' => (is => "rw", isa => "Num");
22 15 has 'details' => (is => "rw", isa => "ArrayRef");
23 15 has '_enormous_num_cb' => (is => "rw", isa => "Maybe[CodeRef]");
24 15 has 'exit' => (is => "rw", isa => "Num");
25 15 has 'filename' => (is => "rw", isa => "Str");
26 15 has '_is_vms' => (is => "rw", isa => "Bool");
27 15 has 'max' => (is => "rw", isa => "Num");
28 15 has 'ok' => (is => "rw", isa => "Num");
29 15 has 'passing' => (is => "rw", isa => "Bool");
30 15 has 'seen' => (is => "rw", isa => "Num");
31 15 has 'skip' => (is => "rw", isa => "Num");
32 15 has 'skip_all' => (is => "rw", isa => "Str");
33 15 has 'skip_reason' => (is => "rw", isa => "Str");
34 15 has 'todo' => (is => "rw", isa => "Num");
35 15 has 'wait' => (is => "rw", isa => "Num");
36  
37 =head1 METHODS
38  
39 =head2 $self->_calc_passing()
40  
41 Calculates whether the test file has passed.
42  
43 =cut
44  
45 sub _is_skip_all
46 55 ▶{
Subroutine _is_skip_all: called CC=2 SCAR=6.9
47 55 my $self = shift;
48  
49 55 ▶ return (($self->max() == 0) && defined($self->skip_all()));
Condition100%3/3
$self->max == 0 && defined $self->skip_all
!ll&&!rl&&r
4753
MC/DC100%2/2
$self->max == 0 && defined $self->skip_all
$self->max == 0 defined $self->skip_all
Truth table100%3/3
A && B
A= $self->max == 0B= defined $self->skip_all
ABresult
0X0
100
111
50 }
51  
52 sub _is_all_tests_passed
53 52 ▶{
Subroutine _is_all_tests_passed: called CC=4 SCAR=13.9
54 52 my $self = shift;
55  
56 return
57 (
58 52 ▶ $self->max && $self->seen
Condition88%8/9
$self->max && $self->seen && $self->max == $self->seen && $self->max == $self->ok
!ll&&!rl&&r
9934
$self->max and $self->seen and $self->max == $self->seen
!ll&&!rl&&r
5443
$self->max and $self->seen
!ll&&!rl&&r
5047
MC/DC75%3/4
$self->max && $self->seen && $self->max == $self->seen && $self->max == $self->ok
$self->max $self->seen $self->max == $self->seen $self->max == $self->ok
Truth table80%4/5
A and B and C && D
A= $self->maxB= $self->seenC= $self->max == $self->seenD= $self->max == $self->ok
ABCDresult
0XXX0
10XX0
110X0
11100
11111
59 && ($self->max == $self->seen)
60 && ($self->max == $self->ok)
61 );
62 }
63  
64 sub _calc_passing
65 55 ▶{
Subroutine _calc_passing: called CC=2 SCAR=6.9
66 55 my $self = shift;
67  
68 55 ▶ return ($self->_is_skip_all() || $self->_is_all_tests_passed());
Condition100%3/3
$self->_is_skip_all || $self->_is_all_tests_passed
l!l&&r!l&&!r
33418
MC/DC100%2/2
$self->_is_skip_all || $self->_is_all_tests_passed
$self->_is_skip_all $self->_is_all_tests_passed
Truth table100%3/3
A || B
A= $self->_is_skip_allB= $self->_is_all_tests_passed
ABresult
1X1
011
000
69 }
70  
71 =head2 $self->determine_passing()
72  
73 Calculates whether the test file has passed and caches it in the passing()
74 slot.
75  
76 =cut
77  
78 sub determine_passing
79 55 ▶{
Subroutine determine_passing: called CC=2 SCAR=6.9
Pod documented
80 55 my $self = shift;
81 55 ▶ $self->passing($self->_calc_passing() ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$self->_calc_passing ? : 37 18 55
82 }
83  
84 =head2 $self->last_detail()
85  
86 Returns the last detail.
87  
88 =cut
89  
90 sub last_detail
91 442 ▶{
Subroutine last_detail: called CC=1 SCAR=0.0
Pod documented
92 442 my $self = shift;
93  
94 442 return $self->details->[-1];
95 }
96  
97 sub _calc_enormous_event_num
98 208 ▶{
Subroutine _calc_enormous_event_num: called CC=1 SCAR=0.0
99 208 my $self = shift;
100  
101 208 return 100_000;
102 }
103  
104 sub _is_enormous_event_num
105 208 ▶{
Subroutine _is_enormous_event_num: called CC=3 SCAR=12.0
106 208 my $self = shift;
107  
108 208 my $large_num = $self->_calc_enormous_event_num();
109  
110 return
111 208 ▶ +($self->_event->number > $large_num)
Condition50%3/6
$self->_event->number > $large_num && $self->_event->number > ($self->max || $large_num)
!ll&&!rl&&r
20107
$self->max || $large_num
l!l&&r!l&&!r
700
MC/DC50%1/2
$self->_event->number > $large_num && $self->_event->number > ($self->max || $large_num)
$self->_event->number > $large_num $self->_event->number > ($self->max || $large_num)
MC/DC0%0/2
$self->max || $large_num
$self->max $large_num
Truth table66%2/3
A && B
A= $self->_event->number > $large_numB= $self->_event->number > ($self->max || $large_num)
ABresult
0X0
100
111
Truth table33%1/3
A || B
A= $self->maxB= $large_num
ABresult
1X1
011
000
112 &&
113 ($self->_event->number > ($self->max || $large_num))
114 ;
115 }
116  
117 sub _init_details_obj_instance
118 201 ▶{
Subroutine _init_details_obj_instance: called CC=1 SCAR=0.0
119 201 my ($self, $args) = @_;
120 201 return Test::Run::Straps::StrapsDetailsObj->new($args);
121 }
122  
123 sub _handle_event_main
124 208 ▶{
Subroutine _handle_event_main: called CC=1 SCAR=0.0
125 208 my $self = shift;
126  
127 208 $self->_inc_seen();
128 208 $self->_update_by_labeled_test_event();
129 208 $self->_update_if_pass();
130 208 $self->_update_details_wrapper();
131 }
132  
133 sub _def_or_blank
134 804 ▶{
Subroutine _def_or_blank: called CC=2 SCAR=6.9
135 804 my $value = shift;
136  
137 804 ▶ return defined($value) ? $value : "";
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 795 9 804
138 }
139  
140 sub _defined_hash_values
141 201 ▶{
Subroutine _defined_hash_values: called CC=1 SCAR=0.0
142 201 my ($self, $hash) = @_;
143  
144 return
145 {
146 map
147 201 { $_ => _def_or_blank($hash->{$_}) }
148 keys(%$hash)
149 };
150 }
151  
152 sub _calc_always_def_details_initializer
153 201 ▶{
Subroutine _calc_always_def_details_initializer: called CC=1 SCAR=0.0
154 201 my $self = shift;
155  
156 201 my $event = $self->_event;
157  
158 return
159 {
160 201 actual_ok => scalar($event->is_ok()),
161 name => $event->description,
162 type => lc($event->directive),
163 reason => $event->explanation,
164 };
165 }
166  
167 sub _calc_defined_details
168 201 ▶{
Subroutine _calc_defined_details: called CC=1 SCAR=0.0
169 201 my $self = shift;
170  
171 201 $self->_defined_hash_values(
172 $self->_calc_always_def_details_initializer()
173 );
174 }
175  
176 sub _calc_details
177 201 ▶{
Subroutine _calc_details: called CC=1 SCAR=0.0
178 201 my $self = shift;
179  
180 return
181 $self->_init_details_obj_instance(
182 {
183 ok => $self->_is_event_pass(),
184 201 %{$self->_calc_defined_details()},
185 }
186 );
187 }
188  
189 sub _update_details
190 201 ▶{
Subroutine _update_details: called CC=1 SCAR=0.0
191 201 my ($self) = @_;
192  
193 201 $self->details->[$self->_event->number - 1] = $self->_calc_details();
194  
195 201 return ;
196 }
197  
198 sub _update_skip_event
199 5 ▶{
Subroutine _update_skip_event: called CC=1 SCAR=0.0
200 5 my $self = shift;
201  
202 5 $self->inc_field('skip');
203  
204 5 return;
205 }
206  
207 sub _update_if_pass
208 208 ▶{
Subroutine _update_if_pass: called CC=2 SCAR=6.9
209 208 my $self = shift;
210  
211 208 ▶ if ($self->_is_event_pass())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_event_pass) 178 30 208
212 {
213 178 $self->inc_field('ok');
214 }
215 }
216  
217 sub _handle_enormous_event_num
218 7 ▶{
Subroutine _handle_enormous_event_num: called CC=1 SCAR=0.0
219 7 my $self = shift;
220  
221 7 return $self->_enormous_num_cb->();
222 }
223  
224 sub _update_todo_event
225 16 ▶{
Subroutine _update_todo_event: called CC=2 SCAR=6.9
226 16 my $self = shift;
227  
228 16 $self->inc_field('todo');
229  
230 16 ▶ if ($self->_event->is_actual_ok())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_event->is_actual_ok) 8 8 16
231 {
232 8 $self->inc_field('bonus');
233 }
234  
235 16 return;
236 }
237  
238  
239 sub _inc_seen
240 208 ▶{
Subroutine _inc_seen: called CC=1 SCAR=0.0
241 208 my $self = shift;
242  
243 208 $self->inc_field('seen');
244 }
245  
246 =head2 $self->handle_event({event => $event, enormous_num_cb => sub {...}});
247  
248 Updates the state of the details using a new TAP::Parser event - $event .
249 C<enormous_num_cb> points to a subroutine reference that is the callback for
250 handling enormous numbers.
251  
252 =cut
253  
254 sub _setup_event
255 208 ▶{
Subroutine _setup_event: called CC=1 SCAR=0.0
256 208 my ($self, $args) = @_;
257  
258 208 $self->_event($args->{event});
259 208 $self->_enormous_num_cb($args->{enormous_num_cb});
260  
261 208 return ;
262 }
263  
264 sub _detach_event
265 208 ▶{
Subroutine _detach_event: called CC=1 SCAR=0.0
266 208 my ($self) = @_;
267  
268 208 $self->_event(undef);
269 208 $self->_enormous_num_cb(undef);
270 }
271  
272 sub handle_event
273 208 ▶{
Subroutine handle_event: called CC=1 SCAR=0.0
Pod documented
274 208 my ($self, $args) = @_;
275  
276 208 $self->_setup_event($args);
277  
278 208 $self->_handle_event_main();
279  
280 208 $self->_detach_event();
281 }
282  
283 sub _update_details_wrapper
284 208 ▶{
Subroutine _update_details_wrapper: called CC=2 SCAR=6.9
285 208 my $self = shift;
286  
287 208 ▶ if ($self->_is_enormous_event_num())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_enormous_event_num) { } 7 201 208
288 {
289 7 $self->_handle_enormous_event_num();
290 }
291 else
292 {
293 201 $self->_update_details();
294 }
295 }
296  
297 sub _update_by_labeled_test_event
298 208 ▶{
Subroutine _update_by_labeled_test_event: called CC=3 SCAR=11.0
299 208 my $self = shift;
300  
301 208 ▶ if ($self->_event->has_todo())
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_event->has_todo) { } 16 192 208
elsif ($self->_event->has_skip) { } 5 187 192
302 {
303 16 $self->_update_todo_event();
304 }
305 elsif ($self->_event->has_skip())
306 {
307 5 $self->_update_skip_event();
308 }
309  
310 208 return;
311 }
312  
313 =head2 $self->update_skip_reason($detail)
314  
315 Updates the skip reason according to the detail $detail.
316  
317 =cut
318  
319 sub _get_skip_reason
320 5 ▶{
Subroutine _get_skip_reason: called CC=3 SCAR=15.1
321 5 my ($self, $detail) = @_;
322  
323 5 ▶ if (!defined($self->skip_reason))
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $self->skip_reason) { } 5 0 5
elsif ($self->skip_reason ne $detail->reason) { } 0 0 0
324 {
325 5 return $detail->reason();
326 }
327 elsif ($self->skip_reason ne $detail->reason())
328 {
329 0 return "various reasons";
330 }
331 else
332 {
333 0 return $self->skip_reason;
334 }
335 }
336  
337 sub _real_update_skip_reason
338 5 ▶{
Subroutine _real_update_skip_reason: called CC=1 SCAR=0.0
339 5 my ($self, $detail) = @_;
340  
341 5 $self->skip_reason($self->_get_skip_reason($detail));
342 }
343  
344 sub update_skip_reason
345 180 ▶{
Subroutine update_skip_reason: called CC=2 SCAR=6.9
Pod documented
346 180 my ($self, $detail) = @_;
347  
348 180 ▶ if ($detail->type eq "skip")
Branch: 1 branch
BranchTrueFalseTotal
if ($detail->type eq "skip") 5 175 180
349 {
350 5 $self->_real_update_skip_reason($detail);
351 }
352 }
353  
354 sub _get_failed_details
355 55 ▶{
Subroutine _get_failed_details: called CC=1 SCAR=0.0
356 55 my $self = shift;
357  
358 55 my $details = $self->details;
359  
360 55 return [ grep {! $details->[$_-1]->{ok} } (1 .. @$details) ];
361 }
362  
363 =head2 $self->get_failed_obj_params
364  
365 Returns a key value array ref of params for initializing the failed-object.
366  
367 =cut
368  
369 sub get_failed_obj_params
370 6 ▶{
Subroutine get_failed_obj_params: called CC=1 SCAR=0.0
Pod documented
371 6 my $self = shift;
372  
373 return
374 [
375 6 estat => $self->exit(),
376 wstat => $self->wait(),
377 name => $self->filename(),
378 ];
379 }
380  
381 =head2 $self->update_based_on_last_detail()
382  
383 Check if the last_detail is OK, and if so update the skip_reason
384 based on it.
385  
386 =cut
387  
388 sub update_based_on_last_detail
389 208 ▶{
Subroutine update_based_on_last_detail: called CC=2 SCAR=6.9
Pod documented
390 208 my $self = shift;
391  
392 208 my $detail = $self->last_detail();
393  
394 208 ▶ if ( $detail->ok() )
Branch: 1 branch
BranchTrueFalseTotal
if ($detail->ok) 180 28 208
395 {
396 180 $self->update_skip_reason($detail);
397 }
398  
399 208 return;
400 }
401  
402 =head2 $self->in_the_middle()
403  
404 Checks if the tests are in the middle - already some were seen but the
405 end was not reached.
406  
407 =cut
408  
409 sub in_the_middle
410 52 ▶{
Subroutine in_the_middle: called CC=2 SCAR=7.1
Pod documented
411 52 my $self = shift;
412  
413 52 ▶ return ($self->seen() && ($self->seen() > $self->max()));
Condition66%2/3
$self->seen && $self->seen > $self->max
!ll&&!rl&&r
4660
MC/DC0%0/2
$self->seen && $self->seen > $self->max
$self->seen $self->seen > $self->max
Truth table66%2/3
A && B
A= $self->seenB= $self->seen > $self->max
ABresult
0X0
100
111
414 }
415  
416 sub _wait2exit_POSIX
417 55 ▶{
Subroutine _wait2exit_POSIX: called CC=1 SCAR=0.0
418 55 my ($self, $wait) = @_;
419  
420 55 return POSIX::WEXITSTATUS($wait);
421 }
422  
423 sub _wait2exit_no_POSIX
424 0 ▶{
Subroutine _wait2exit_no_POSIX: not called CC=1 SCAR=6.9
425 0 my ($self, $wait) = @_;
426  
427 0 return ($wait >> 8);
428 }
429  
430 15 eval { require POSIX; POSIX::WEXITSTATUS($?); };
431  
432 15 ▶*_wait2exit = ($@ ? \&_wait2exit_no_POSIX : \&_wait2exit_POSIX);
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 15 15
433  
434 sub _calc_all_process_status
435 55 ▶{
Subroutine _calc_all_process_status: called CC=4 SCAR=14.2
436 55 my $self = shift;
437  
438 # TODO - factor out the code.
439 55 $self->wait($?);
440  
441 55 ▶ if ($self->wait() && $self->_is_vms())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->wait and $self->_is_vms) { } 0 55 55
Condition66%2/3
$self->wait and $self->_is_vms
!ll&&!rl&&r
4960
MC/DC0%0/2
$self->wait and $self->_is_vms
$self->wait $self->_is_vms
Truth table66%2/3
A and B
A= $self->waitB= $self->_is_vms
ABresult
0X0
100
111
442 {
443 0 eval q{use vmsish "status"; $self->exit($?);};
444 }
445 else
446 {
447 55 $self->exit($self->_wait2exit($self->wait()));
448 }
449 # It is possible $? is set agains because of the use vmsish
450 # call.
451 55 ▶ if ($? != 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 6 49 55
452 {
453 6 $self->passing(0);
454 }
455  
456 55 return;
457 }
458  
459 =head2 $self->bonus()
460  
461 Number of TODO tests that unexpectedly passed.
462  
463 =head2 $self->details()
464  
465 An array containing the details of the individual checks in the test file.
466  
467 =head2 $self->exit()
468  
469 The exit code of the test script.
470  
471 =head2 $self->filename()
472  
473 The filename of the test script.
474  
475 =head2 $self->max()
476  
477 The number of planned tests.
478  
479 =head2 $self-ok()
480  
481 The number of tests that passed.
482  
483 =head2 $self->passing()
484  
485 A boolean value that indicates whether the entire test script is considered
486 a success or not.
487  
488 =head2 $self->seen()
489  
490 The number of tests that were actually run.
491  
492 =head2 $self->skip()
493  
494 The number of skipped tests.
495  
496 =head2 $self->skip_all()
497  
498 This field will contain the reason for why the entire test script was skipped,
499 in cases when it was.
500  
501 =head2 $self->skip_reason()
502  
503 The skip reason for the last skipped test that specified such a reason.
504  
505 =head2 $self->todo()
506  
507 The number of "Todo" tests that were encountered.
508  
509 =head2 $self->wait()
510  
511 The wait code of the test script.
512  
513 =head1 SEE ALSO
514  
515 L<Test::Run::Base::Struct>, L<Test::Run::Obj>, L<Test::Run::Core>
516  
517 =head1 LICENSE
518  
519 This file is licensed under the MIT X11 License:
520  
521 http://www.opensource.org/licenses/mit-license.php
522  
523 =head1 AUTHOR
524  
525 Shlomi Fish, L<http://www.shlomifish.org/>.
526  
527 =cut
528  
529 15 1;
530  
« Run/Obj/CanonFailedObj.pm ↑ Summary Run/Obj/IntOrUnknown.pm »