Run/Core.pm

filter: Statementstmt 95.4% 521 / 546 Branchbran 80.3% 45 / 56 Conditioncond 42.8% 3 / 7 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 95.8% 161 / 168 Podpod 100% 3 / 3 totaltotal 93.6% 734 / 784 CC 35 SCAR 3.9
CC
35
Cov
93%
_show_success_or_failure
4.1
_strap_header_handler
3.3
_time_single_test
3.1
CRAP 1.5
« Run/Obj/TotObj.pm ↑ Summary Run/Base.pm »
1 package Test::Run::Core;
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 15 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 15 extends('Test::Run::Base::PlugHelpers');
9  
10  
11 15 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 15 ▶use MRO::Compat;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 15 ▶use List::MoreUtils ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 15 ▶use Fatal qw(opendir);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 15 ▶use Time::HiRes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20 15 ▶use List::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 15 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 15 ▶use Test::Run::Assert qw/ assert /;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 15 ▶use Test::Run::Obj::Error ();
Subroutine BEGIN: called CC=1 SCAR=0.0
26 15 ▶use Test::Run::Straps ();
Subroutine BEGIN: called CC=1 SCAR=0.0
27 15 ▶use Test::Run::Obj::IntOrUnknown ();
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 =head1 NAME
30  
31 Test::Run::Core - Base class to run standard TAP scripts.
32  
33 =head1 VERSION
34  
35 Version 0.0306
36  
37 =cut
38  
39 15 $VERSION = '0.0306';
40  
41 15 $ENV{HARNESS_ACTIVE} = 1;
42 15 $ENV{HARNESS_NG_VERSION} = $VERSION;
43  
44 END
45 15 ▶{
Subroutine END: called CC=1 SCAR=0.0
46 # For VMS.
47 15 delete $ENV{HARNESS_ACTIVE};
48 15 delete $ENV{HARNESS_NG_VERSION};
49 }
50  
51 15 has "_bonusmsg" => (is => "rw", isa => "Str");
52 has "dir_files" => (is => "rw", isa => "ArrayRef", lazy => 1,
53 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
54 15 );
55 15 has "_new_dir_files" => (is => "rw", isa => "Maybe[ArrayRef]");
56 15 has "failed_tests" => (is => "rw", isa => "HashRef");
57 15 has "format_columns" => (is => "rw", isa => "Num");
58 15 has "last_test_elapsed" => (is => "rw", isa => "Str");
59 15 has "last_test_obj" => (is => "rw", isa => "Test::Run::Obj::TestObj");
60 15 has "last_test_results" => (is => "rw", isa => "Test::Run::Straps::StrapsTotalsObj");
61 15 has "list_len" => (is => "rw", isa => "Num", default => 0);
62 15 has "max_namelen" => (is => "rw", isa => "Num");
63  
64 # I don't know for sure what output is. It is Test::Run::Output in
65 # Test::Run::Plugin::CmdLine::Output but could be different elsewhere.
66 15 has "output" => (is => "rw", isa => "Ref");
67 15 has "_start_time" => (is => "rw", isa => "Num");
68 15 has "Strap" => (is => "rw", isa => "Test::Run::Straps",
69 lazy => 1, builder => "_get_new_strap"
70 );
71 15 has "tot" => (is => "rw", isa => "Test::Run::Obj::TotObj");
72 15 has "width" => (is => "rw", isa => "Num");
73  
74 # Private Simple Params of _get_private_simple_params
75 15 has "Columns" => (is => "rw", isa => "Num", default => "80");
76 15 has "Debug" => (is => "rw", isa => "Bool");
77 15 has "Leaked_Dir" => (is => "rw", isa => "Str");
78 15 has "NoTty" => (is => "rw", isa => "Bool");
79 15 has "Switches" => (is => "rw", isa => "Maybe[Str]", default => "-w",);
80 15 has "Switches_Env" => (is => "rw", isa => "Maybe[Str]");
81 15 has "test_files" => (is => "rw", isa => "ArrayRef");
82 has "test_files_data" => (is => "rw", isa => "HashRef",
83 52 ▶ default => sub { +{} },
Subroutine __ANON__: called CC=1 SCAR=0.0
84 15 );
85 15 has "Test_Interpreter" => (is => "rw", isa => "Maybe[Str]");
86 15 has "Timer" => (is => "rw", isa => "Bool");
87 15 has "Verbose" => (is => "rw", isa => "Bool");
88  
89 sub _get_new_strap
90 52 ▶{
Subroutine _get_new_strap: called CC=1 SCAR=0.0
91 52 my $self = shift;
92  
93 52 return $self->create_pluggable_helper_obj(
94 {
95 id => "straps",
96 args => {},
97 }
98 );
99 }
100  
101 =head2 BUILD
102  
103 For Moose.
104  
105 =cut
106  
107 sub BUILD
108 52 ▶{
Subroutine BUILD: called CC=1 SCAR=0.0
Pod documented
109 52 my $self = shift;
110  
111 52 $self->register_pluggable_helper(
112 {
113 id => "straps",
114 base => "Test::Run::Straps",
115 collect_plugins_method => "private_straps_plugins",
116 },
117 );
118  
119 52 $self->register_pluggable_helper(
120 {
121 id => "failed",
122 base => "Test::Run::Obj::FailedObj",
123 collect_plugins_method => "private_failed_obj_plugins",
124 },
125 );
126  
127 52 $self->register_pluggable_helper(
128 {
129 id => "test",
130 base => "Test::Run::Obj::TestObj",
131 collect_plugins_method => "private_test_obj_plugins",
132 },
133 );
134  
135 52 $self->register_pluggable_helper(
136 {
137 id => "tot",
138 base => "Test::Run::Obj::TotObj",
139 collect_plugins_method => "private_tot_obj_plugins",
140 },
141 );
142  
143 52 $self->register_pluggable_helper(
144 {
145 id => "canon_failed",
146 base => "Test::Run::Obj::CanonFailedObj",
147 collect_plugins_method => "private_canon_failed_obj_plugins",
148 },
149 );
150  
151 52 $self->_register_obj_formatter(
152 {
153 name => "fail_other_except",
154 format => "Failed %(_get_fail_test_scripts_string)s%(_get_fail_tests_good_percent_string)s.%(_get_sub_percent_msg)s\n"
155 },
156 );
157  
158 52 return 0;
159 }
160  
161 =head2 $self->helpers_base_namespace()
162  
163 See L<Test::Run::Base::PlugHelpers>.
164  
165 =cut
166  
167 sub helpers_base_namespace
168 201 ▶{
Subroutine helpers_base_namespace: called CC=1 SCAR=0.0
Pod documented
169 201 my $self = shift;
170  
171 201 return "Test::Run::Core::__HelperObjects";
172 }
173  
174 =head2 Object Parameters
175  
176 These parameters are accessors. They can be set at object creation by passing
177 their name along with a value on the constructor (along with the compulsory
178 C<'test_files'> argument):
179  
180 my $tester = Test::Run::Obj->new(
181 {
182 'test_files' => \@mytests,
183 'Verbose' => 1,
184 }
185 );
186  
187 Alternatively, before C<runtests()> is called, they can be set by passing a
188 value to their accessor:
189  
190 $tester->Verbose(1);
191  
192 =over 4
193  
194 =item C<$self-E<gt>Verbose()>
195  
196 The object variable C<$self-E<gt>Verbose()> can be used to let C<runtests()>
197 display the standard output of the script without altering the behavior
198 otherwise. The F<runprove> utility's C<-v> flag will set this.
199  
200 =item C<$self-E<gt>Leaked_Dir()>
201  
202 When set to the name of a directory, C<$tester> will check after each
203 test whether new files appeared in that directory, and report them as
204  
205 LEAKED FILES: scr.tmp 0 my.db
206  
207 If relative, directory name is with respect to the current directory at
208 the moment C<$tester-E<gt>runtests()> was called. Putting the absolute path
209 into C<Leaked_Dir> will give more predictable results.
210  
211 =item C<$self-E<gt>Debug()>
212  
213 If C<$self-E<gt>Debug()> is true, Test::Run will print debugging information
214 about itself as it runs the tests. This is different from
215 C<$self-E<gt>Verbose()>, which prints the output from the test being run.
216  
217 =item C<$self-E<gt>Columns()>
218  
219 This value will be used for the width of the terminal. If it is not
220 set then it will default to 80.
221  
222 =item C<$self-E<gt>Timer()>
223  
224 If set to true, and C<Time::HiRes> is available, print elapsed seconds
225 after each test file.
226  
227 =item C<$self-E<gt>NoTty()>
228  
229 When set to a true value, forces it to behave as though STDOUT were
230 not a console. You may need to set this if you don't want harness to
231 output more frequent progress messages using carriage returns. Some
232 consoles may not handle carriage returns properly (which results in a
233 somewhat messy output).
234  
235 =item C<$self-E<gt>Test_Interprter()>
236  
237 Usually your tests will be run by C<$^X>, the currently-executing Perl.
238 However, you may want to have it run by a different executable, such as
239 a threading perl, or a different version.
240  
241 =item C<$self-E<gt>Switches()> and C<$self-E<gt>Switches_Env()>
242  
243 These two values will be prepended to the switches used to invoke perl on
244 each test. For example, setting one of them to C<-W> will
245 run all tests with all warnings enabled.
246  
247 The difference between them is that C<Switches_Env()> is expected to be
248 filled in by the environment and C<Switches()> from other sources (like the
249 programmer).
250  
251 =back
252  
253 =head2 METHODS
254  
255 Test::Run currently has only one interface method.
256  
257 =head2 $tester->runtests()
258  
259 my $all_ok = $tester->runtests()
260  
261 Runs the tests, see if they are OK. Returns true if they are OK, or
262 throw an exception otherwise.
263  
264 =cut
265  
266 =head2 $self->_report_leaked_files({leaked_files => [@files]})
267  
268 [This is a method that needs to be over-rided.]
269  
270 Should report (or ignore) the files that were leaked in the directories
271 that were specifies as leaking directories.
272  
273 =cut
274  
275 =head2 $self->_report_failed_with_results_seen({%args})
276  
277 [This is a method that needs to be over-rided.]
278  
279 Should report (or ignore) the failed tests in the test file.
280  
281 Arguments are:
282  
283 =over 4
284  
285 =item * test_struct
286  
287 The test struct as returned by straps.
288  
289 =item * filename
290  
291 The filename
292  
293 =item * estatus
294  
295 Exit status.
296  
297 =item * wstatus
298  
299 Wait status.
300  
301 =item * results
302  
303 The results of the test.
304  
305 =back
306  
307 =cut
308  
309 =head2 $self->_recheck_dir_files()
310  
311 Called to recheck that the dir files is OK.
312  
313 =cut
314  
315 sub _recheck_dir_files
316 55 ▶{
Subroutine _recheck_dir_files: called CC=2 SCAR=6.9
317 55 my $self = shift;
318  
319 55 ▶ if (defined($self->Leaked_Dir()))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->Leaked_Dir) 2 53 55
320 {
321 2 return $self->_real_recheck_dir_files();
322 }
323 }
324  
325 sub _calc_leaked_files_since_last_update
326 2 ▶{
Subroutine _calc_leaked_files_since_last_update: called CC=1 SCAR=0.0
327 2 my $self = shift;
328  
329 2 my %found;
330  
331 2 @found{@{$self->_new_dir_files()}} = (1) x @{$self->_new_dir_files()};
332  
333 2 delete(@found{@{$self->dir_files()}});
334  
335 2 return [sort keys(%found)];
336 }
337  
338 sub _real_recheck_dir_files
339 2 ▶{
Subroutine _real_recheck_dir_files: called CC=1 SCAR=0.0
340 2 my $self = shift;
341  
342 2 $self->_new_dir_files($self->_get_dir_files());
343  
344 2 $self->_report_leaked_files(
345 {
346 leaked_files => $self->_calc_leaked_files_since_last_update()
347 }
348 );
349 2 $self->_update_dir_files();
350 }
351  
352 sub _update_dir_files
353 2 ▶{
Subroutine _update_dir_files: called CC=1 SCAR=0.0
354 2 my $self = shift;
355  
356 2 $self->dir_files($self->_new_dir_files());
357  
358 # Reset it to prevent dangerous behaviour.
359 2 $self->_new_dir_files(undef);
360  
361 2 return;
362 }
363  
364 sub _glob_dir
365 4 ▶{
Subroutine _glob_dir: called CC=1 SCAR=0.0
366 4 my ($self, $dirname) = @_;
367  
368 4 my $dir;
369 4 opendir $dir, $dirname;
370 4 my @contents = readdir($dir);
371 4 closedir($dir);
372  
373 4 return [File::Spec->no_upwards(@contents)];
374 }
375  
376 sub _get_num_tests_files
377 51 ▶{
Subroutine _get_num_tests_files: called CC=1 SCAR=0.0
378 51 my $self = shift;
379  
380 51 return scalar(@{$self->test_files()});
381 }
382  
383 sub _get_tot_counter_tests
384 51 ▶{
Subroutine _get_tot_counter_tests: called CC=1 SCAR=0.0
385 51 my $self = shift;
386  
387 51 return [ tests => $self->_get_num_tests_files() ];
388 }
389  
390 sub _init_tot_obj_instance
391 51 ▶{
Subroutine _init_tot_obj_instance: called CC=1 SCAR=0.0
392 51 my $self = shift;
393 return $self->create_pluggable_helper_obj(
394 {
395 id => "tot",
396 51 args => { @{$self->_get_tot_counter_tests()} },
397 }
398 );
399 }
400  
401 sub _init_tot
402 51 ▶{
Subroutine _init_tot: called CC=1 SCAR=0.0
403 51 my $self = shift;
404 51 $self->tot(
405 $self->_init_tot_obj_instance()
406 );
407 }
408  
409 sub _tot_inc
410 115 ▶{
Subroutine _tot_inc: called CC=1 SCAR=0.0
411 115 my ($self, $field) = @_;
412  
413 115 $self->tot()->inc($field);
414 }
415  
416 sub _tot_add_results
417 55 ▶{
Subroutine _tot_add_results: called CC=1 SCAR=0.0
418 55 my ($self, $results) = @_;
419  
420 55 return $self->tot->add_results($results);
421 }
422  
423 sub _create_failed_obj_instance
424 19 ▶{
Subroutine _create_failed_obj_instance: called CC=1 SCAR=0.0
425 19 my $self = shift;
426 19 my $args = shift;
427 19 return $self->create_pluggable_helper_obj(
428 {
429 id => "failed",
430 args => $args,
431 }
432 );
433 }
434  
435 sub _create_test_obj_instance
436 55 ▶{
Subroutine _create_test_obj_instance: called CC=1 SCAR=0.0
437 55 my ($self, $args) = @_;
438 55 return $self->create_pluggable_helper_obj(
439 {
440 id => "test",
441 args => $args,
442 }
443 );
444 }
445  
446 sub _is_failed_and_max
447 24 ▶{
Subroutine _is_failed_and_max: called CC=1 SCAR=0.0
448 24 my $self = shift;
449  
450 24 return $self->last_test_obj->is_failed_and_max();
451 }
452  
453 sub _strap_test_handler
454 208 ▶{
Subroutine _strap_test_handler: called CC=1 SCAR=0.0
455 208 my ($self, $args) = @_;
456  
457 208 $args->{totals}->update_based_on_last_detail();
458  
459 208 $self->_report_test_progress($args);
460  
461 208 return;
462 }
463  
464 sub _strap_header_handler
465 52 ▶{
Subroutine _strap_header_handler: called CC=3 SCAR=12.0
466 52 my ($self, $args) = @_;
467  
468 52 my $totals = $args->{totals};
469  
470 52 ▶ if ($self->Strap()->_seen_header())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Strap->_seen_header) 0 52 52
471 {
472 0 warn "Test header seen more than once!\n";
473 }
474  
475 52 $self->Strap()->_inc_seen_header();
476  
477 52 ▶ if ($totals->in_the_middle())
Branch: 1 branch
BranchTrueFalseTotal
if ($totals->in_the_middle) 0 52 52
478 {
479 0 warn "1..M can only appear at the beginning or end of tests\n";
480 }
481  
482 52 return;
483 }
484  
485  
486 sub _tap_event_strap_callback
487 289 ▶{
Subroutine _tap_event_strap_callback: called CC=1 SCAR=0.0
488 289 my ($self, $args) = @_;
489  
490 289 $self->_report_tap_event($args);
491  
492 289 return $self->_tap_event_handle_strap($args);
493 }
494  
495 sub _tap_event__calc_conds
496 289 ▶{
Subroutine _tap_event__calc_conds: called CC=1 SCAR=0.0
497 289 my $self = shift;
498  
499 return
500 [
501 289 { cond => "is_plan", handler => "_strap_header_handler", },
502 { cond => "is_bailout", handler => "_strap_bailout_handler", },
503 { cond => "is_test", handler => "_strap_test_handler"},
504 ];
505 }
506  
507 sub _tap_event_handle_strap
508 289 ▶{
Subroutine _tap_event_handle_strap: called CC=3 SCAR=11.0
509 289 my ($self, $args) = @_;
510 289 my $event = $args->{event};
511  
512 289 foreach my $c (@{$self->_tap_event__calc_conds()})
513 {
514 761 my $cond = $c->{cond};
515 761 my $handler = $c->{handler};
516  
517 761 ▶ if ($event->$cond())
Branch: 1 branch
BranchTrueFalseTotal
if ($event->$cond) 262 499 761
518 {
519 262 return $self->$handler($args);
520 }
521 }
522 27 return;
523 }
524  
525 =begin _private
526  
527 =over 4
528  
529 =item B<_all_ok>
530  
531 my $ok = $self->_all_ok();
532  
533 Tells you if the current test run is OK or not.
534  
535 =cut
536  
537 sub _all_ok
538 88 ▶{
Subroutine _all_ok: called CC=1 SCAR=0.0
539 88 my $self = shift;
540 88 return $self->tot->all_ok();
541 }
542  
543 =back
544  
545 =cut
546  
547 sub _get_dir_files
548 4 ▶{
Subroutine _get_dir_files: called CC=1 SCAR=0.0
549 4 my $self = shift;
550  
551 4 return $self->_glob_dir($self->Leaked_Dir());
552 }
553  
554 sub _calc_strap_callback_map
555 346 ▶{
Subroutine _calc_strap_callback_map: called CC=1 SCAR=0.0
556 return
557 {
558 346 "tap_event" => "_tap_event_strap_callback",
559 "report_start_env" => "_report_script_start_environment",
560 "could_not_run_script" => "_report_could_not_run_script",
561 "test_file_opening_error" => "_handle_test_file_opening_error",
562 "test_file_closing_error" => "_handle_test_file_closing_error",
563 };
564 }
565  
566 sub _strap_callback
567 346 ▶{
Subroutine _strap_callback: called CC=1 SCAR=0.0
568 346 my ($self, $args) = @_;
569  
570 346 my $type = $args->{type};
571 346 my $cb = $self->_calc_strap_callback_map()->{$type};
572  
573 346 return $self->$cb($args);
574 }
575  
576 sub _inc_bad
577 19 ▶{
Subroutine _inc_bad: called CC=1 SCAR=0.0
578 19 my $self = shift;
579  
580 19 $self->_tot_inc('bad');
581  
582 19 return;
583 }
584  
585 sub _ser_failed_results
586 12 ▶{
Subroutine _ser_failed_results: called CC=1 SCAR=0.0
587 12 my $self = shift;
588  
589 12 return $self->_canonfailed()->get_ser_results();
590 }
591  
592 sub _get_current_time
593 0 ▶{
Subroutine _get_current_time: not called CC=1 SCAR=6.9
594 0 my $self = shift;
595  
596 0 return Time::HiRes::time();
597 }
598  
599 sub _set_start_time
600 57 ▶{
Subroutine _set_start_time: called CC=2 SCAR=8.1
601 57 my $self = shift;
602  
603 57 ▶ if ($self->Timer())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Timer) 0 57 57
604 {
605 0 $self->_start_time($self->_get_current_time());
606 }
607 }
608  
609 sub _get_failed_with_results_seen_msg
610 12 ▶{
Subroutine _get_failed_with_results_seen_msg: called CC=2 SCAR=6.9
611 12 my $self = shift;
612  
613 return
614 12 ▶ $self->_is_failed_and_max()
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_failed_and_max ? : 10 2 12
615 ? $self->_get_failed_and_max_msg()
616 : $self->_get_dont_know_which_tests_failed_msg()
617 ;
618 }
619  
620 sub _get_dont_know_which_tests_failed_msg
621 2 ▶{
Subroutine _get_dont_know_which_tests_failed_msg: called CC=1 SCAR=0.0
622 2 my $self = shift;
623  
624 2 return $self->last_test_obj->_get_dont_know_which_tests_failed_msg();
625 }
626  
627 sub _get_elapsed
628 55 ▶{
Subroutine _get_elapsed: called CC=2 SCAR=7.6
629 55 my $self = shift;
630  
631 55 ▶ if ($self->Timer())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Timer) { } 0 55 55
632 {
633 0 return sprintf(" %8.3fs",
634 $self->_get_current_time() - $self->_start_time()
635 );
636 }
637 else
638 {
639 55 return "";
640 }
641 }
642  
643 sub _set_last_test_elapsed
644 55 ▶{
Subroutine _set_last_test_elapsed: called CC=1 SCAR=0.0
645 55 my $self = shift;
646  
647 55 $self->last_test_elapsed($self->_get_elapsed());
648 }
649  
650 sub _get_copied_strap_fields
651 57 ▶{
Subroutine _get_copied_strap_fields: called CC=1 SCAR=0.0
652 57 return [qw(Debug Test_Interpreter Switches Switches_Env)];
653 }
654  
655 sub _init_strap
656 57 ▶{
Subroutine _init_strap: called CC=1 SCAR=0.0
657 57 my ($self, $args) = @_;
658  
659 57 $self->Strap()->copy_from($self, $self->_get_copied_strap_fields());
660 }
661  
662 sub _get_sub_percent_msg
663 7 ▶{
Subroutine _get_sub_percent_msg: called CC=1 SCAR=0.0
664 7 my $self = shift;
665  
666 7 return $self->tot->get_sub_percent_msg();
667 }
668  
669 sub _handle_passing_test
670 36 ▶{
Subroutine _handle_passing_test: called CC=1 SCAR=0.0
671 36 my $self = shift;
672  
673 36 $self->_process_passing_test();
674 36 $self->_tot_inc('good');
675 }
676  
677 sub _does_test_have_some_oks
678 36 ▶{
Subroutine _does_test_have_some_oks: called CC=1 SCAR=0.0
679 36 my $self = shift;
680  
681 36 return $self->last_test_obj->max();
682 }
683  
684 sub _process_passing_test
685 36 ▶{
Subroutine _process_passing_test: called CC=2 SCAR=6.9
686 36 my $self = shift;
687  
688 36 ▶ if ($self->_does_test_have_some_oks())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_does_test_have_some_oks) { } 33 3 36
689 {
690 33 $self->_process_test_with_some_oks();
691 }
692 else
693 {
694 3 $self->_process_all_skipped_test();
695 }
696 }
697  
698 sub _process_test_with_some_oks
699 33 ▶{
Subroutine _process_test_with_some_oks: called CC=2 SCAR=6.9
700 33 my $self = shift;
701  
702 33 ▶ if ($self->last_test_obj->skipped_or_bonus())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->last_test_obj->skipped_or_bonus) { } 11 22 33
703 {
704 11 return $self->_process_skipped_test();
705 }
706 else
707 {
708 22 return $self->_process_all_ok_test();
709 }
710 }
711  
712 sub _process_all_ok_test
713 22 ▶{
Subroutine _process_all_ok_test: called CC=1 SCAR=0.0
714 22 my ($self) = @_;
715 22 return $self->_report_all_ok_test();
716 }
717  
718 sub _process_all_skipped_test
719 3 ▶{
Subroutine _process_all_skipped_test: called CC=1 SCAR=0.0
720 3 my $self = shift;
721  
722 3 $self->_report_all_skipped_test();
723 3 $self->_tot_inc('skipped');
724  
725 3 return;
726 }
727  
728 sub _fail_other_get_script_names
729 7 ▶{
Subroutine _fail_other_get_script_names: called CC=1 SCAR=0.2
730 7 my $self = shift;
731  
732 0 return [ sort { $a cmp $b } (keys(%{$self->failed_tests()})) ];
733 }
734  
735 sub _fail_other_print_all_tests
736 7 ▶{
Subroutine _fail_other_print_all_tests: called CC=2 SCAR=6.9
737 7 my $self = shift;
738  
739 7 for my $script (@{$self->_fail_other_get_script_names()})
740 {
741 7 $self->_fail_other_report_test($script);
742 }
743 }
744  
745 sub _fail_other_throw_exception
746 7 ▶{
Subroutine _fail_other_throw_exception: called CC=1 SCAR=0.0
747 7 my $self = shift;
748  
749 7 die Test::Run::Obj::Error::TestsFail::Other->new(
750 {text => $self->_get_fail_other_exception_text(),},
751 );
752 }
753  
754 sub _process_skipped_test
755 11 ▶{
Subroutine _process_skipped_test: called CC=1 SCAR=0.0
756 11 my ($self) = @_;
757  
758 11 return $self->_report_skipped_test();
759 }
760  
761  
762  
763 sub _time_single_test
764 57 ▶{
Subroutine _time_single_test: called CC=3 SCAR=11.2
765 57 my ($self, $args) = @_;
766  
767 57 $self->_set_start_time($args);
768  
769 57 $self->_init_strap($args);
770  
771 57 ▶ $self->Strap->callback(sub { return $self->_strap_callback(@_); });
Subroutine __ANON__: called CC=1 SCAR=0.0
772  
773 # We trap exceptions so we can nullify the callback to avoid memory
774 # leaks.
775 57 my $results;
776 eval
777 57 {
778 57 ▶ if (! ($results = $self->Strap()->analyze_file($args->{test_file})))
Branch: 1 branch
BranchTrueFalseTotal
unless ($results = $self->Strap->analyze_file($args->{"test_file"})) 0 55 55
779 {
780 do
781 0 {
782 0 warn $self->Strap()->error(), "\n";
783 0 next;
784 }
785 }
786 };
787  
788 # To avoid circular references
789 57 $self->Strap->callback(undef);
790  
791 57 ▶ if ($@ ne "")
Branch: 1 branch
BranchTrueFalseTotal
if ($@ ne "") 2 55 57
792 {
793 2 die $@;
794 }
795 55 $self->_set_last_test_elapsed($args);
796  
797 55 $self->last_test_results($results);
798  
799 55 return;
800 }
801  
802 sub _fail_no_tests_output
803 1 ▶{
Subroutine _fail_no_tests_output: called CC=1 SCAR=0.0
804 1 my $self = shift;
805 1 die Test::Run::Obj::Error::TestsFail::NoOutput->new(
806 {text => $self->_get_fail_no_tests_output_text(),},
807 );
808 }
809  
810 sub _failed_canon
811 12 ▶{
Subroutine _failed_canon: called CC=1 SCAR=0.0
812 12 my $self = shift;
813  
814 12 return $self->_canonfailed()->canon();
815 }
816  
817 sub _get_failed_and_max_msg
818 10 ▶{
Subroutine _get_failed_and_max_msg: called CC=1 SCAR=0.0
819 10 my $self = shift;
820  
821 10 return $self->last_test_obj->ml()
822 . $self->_ser_failed_results();
823 }
824  
825 sub _canonfailed
826 24 ▶{
Subroutine _canonfailed: called CC=1 SCAR=0.0
827 24 my $self = shift;
828  
829 24 my $canon_obj = $self->_canonfailed_get_canon();
830  
831 24 $canon_obj->add_Failed_and_skipped($self->last_test_obj);
832  
833 24 return $canon_obj;
834 # Originally returning get_ser_results, canon
835 }
836  
837  
838 sub _filter_failed
839 24 ▶{
Subroutine _filter_failed: called CC=1 SCAR=0.0
840 24 my ($self, $failed_ref) = @_;
841 24 return [ List::MoreUtils::uniq(sort { $a <=> $b } @$failed_ref) ];
842 }
843  
844 sub _canonfailed_get_failed
845 24 ▶{
Subroutine _canonfailed_get_failed: called CC=1 SCAR=0.0
846 24 my $self = shift;
847  
848 24 return $self->_filter_failed($self->_get_failed_list());
849 }
850  
851 =head2 $self->_calc_test_struct_ml($results)
852  
853 Calculates the ml(). (See L<Test::Run::Output>) for the test.
854  
855 =cut
856  
857 sub _calc_test_struct_ml
858 0 ▶{
Subroutine _calc_test_struct_ml: not called CC=1 SCAR=6.9
859 0 my $self = shift;
860  
861 0 return "";
862 }
863  
864 sub _calc_last_test_obj_params
865 55 ▶{
Subroutine _calc_last_test_obj_params: called CC=1 SCAR=0.0
866 55 my $self = shift;
867  
868 55 my $results = $self->last_test_results;
869  
870 return
871 [
872 (
873 55 map { $_ => $results->$_(), }
874 (qw(bonus max ok skip_reason skip_all))
875 ),
876 skipped => $results->skip(),
877 'next' => $self->Strap->next_test_num(),
878 failed => $results->_get_failed_details(),
879 ml => $self->_calc_test_struct_ml($results),
880 ];
881 }
882  
883 sub _get_fail_no_tests_run_text
884 0 ▶{
Subroutine _get_fail_no_tests_run_text: not called CC=1 SCAR=6.9
885 0 return "FAILED--no tests were run for some reason.\n"
886 }
887  
888 sub _get_fail_no_tests_output_text
889 1 ▶{
Subroutine _get_fail_no_tests_output_text: called CC=1 SCAR=0.0
890 1 my $self = shift;
891  
892 1 return $self->tot->_get_fail_no_tests_output_text();
893 }
894  
895 sub _get_success_msg
896 15 ▶{
Subroutine _get_success_msg: called CC=1 SCAR=0.0
897 15 my $self = shift;
898 15 return "All tests successful" . $self->_get_bonusmsg() . ".";
899 }
900  
901 sub _fail_no_tests_run
902 0 ▶{
Subroutine _fail_no_tests_run: not called CC=1 SCAR=6.9
903 0 my $self = shift;
904 0 die Test::Run::Obj::Error::TestsFail::NoTestsRun->new(
905 {text => $self->_get_fail_no_tests_run_text(),},
906 );
907 }
908  
909 sub _calc_test_struct
910 55 ▶{
Subroutine _calc_test_struct: called CC=1 SCAR=0.0
911 55 my $self = shift;
912  
913 55 my $results = $self->last_test_results;
914  
915 55 $self->_tot_add_results($results);
916  
917 return $self->last_test_obj(
918 $self->_create_test_obj_instance(
919 {
920 55 @{$self->_calc_last_test_obj_params()},
921 }
922 )
923 );
924 }
925  
926 sub _get_failed_list
927 24 ▶{
Subroutine _get_failed_list: called CC=1 SCAR=0.0
928 24 my $self = shift;
929  
930 24 return $self->last_test_obj->failed;
931 }
932  
933 sub _get_premature_test_dubious_summary
934 2 ▶{
Subroutine _get_premature_test_dubious_summary: called CC=1 SCAR=0.0
935 2 my $self = shift;
936  
937 2 $self->last_test_obj->add_next_to_failed();
938  
939 2 $self->_report_premature_test_dubious_summary();
940  
941 2 return $self->_get_failed_and_max_params();
942 }
943  
944 sub _failed_before_any_test_output
945 1 ▶{
Subroutine _failed_before_any_test_output: called CC=1 SCAR=0.0
946 1 my $self = shift;
947  
948 1 $self->_report_failed_before_any_test_output();
949  
950 1 $self->_inc_bad();
951  
952 1 return $self->_calc_failed_before_any_test_obj();
953 }
954  
955 sub _max_len
956 102 ▶{
Subroutine _max_len: called CC=1 SCAR=0.0
957 102 my ($self, $array_ref) = @_;
958  
959 102 return List::Util::max(map { length($_) } @$array_ref);
960 }
961  
962 # TODO : Add _leader_width here.
963  
964  
965 sub _get_fn_fn
966 57 ▶{
Subroutine _get_fn_fn: called CC=1 SCAR=0.0
967 57 my ($self, $fn) = @_;
968  
969 57 return $fn;
970 }
971  
972 sub _get_fn_ext
973 57 ▶{
Subroutine _get_fn_ext: called CC=2 SCAR=6.9
974 57 my ($self, $fn) = @_;
975  
976 57 ▶ return (($fn =~ /\.(\w+)\z/) ? $1 : "");
Branch: 1 branch
BranchTrueFalseTotal
$fn =~ /\.(\w+)\z/ ? : 4 53 57
977 }
978  
979 sub _get_filename_map_max_len
980 102 ▶{
Subroutine _get_filename_map_max_len: called CC=1 SCAR=0.0
981 102 my ($self, $cb) = @_;
982  
983 return $self->_max_len(
984 114 [ map { $self->$cb($self->_get_test_file_display_path($_)) }
985 102 @{$self->test_files()}
986 ]
987 );
988 }
989  
990 sub _get_max_ext_len
991 51 ▶{
Subroutine _get_max_ext_len: called CC=1 SCAR=0.0
992 51 my $self = shift;
993  
994 51 return $self->_get_filename_map_max_len("_get_fn_ext");
995 }
996  
997 sub _get_max_filename_len
998 51 ▶{
Subroutine _get_max_filename_len: called CC=1 SCAR=0.0
999 51 my $self = shift;
1000  
1001 51 return $self->_get_filename_map_max_len("_get_fn_fn");
1002 }
1003  
1004 =head2 $self->_leader_width()
1005  
1006 Calculates how long the leader should be based on the length of the
1007 maximal test filename.
1008  
1009 =cut
1010  
1011 sub _leader_width
1012 51 ▶{
Subroutine _leader_width: called CC=1 SCAR=0.0
1013 51 my $self = shift;
1014  
1015 51 return $self->_get_max_filename_len() + 3 - $self->_get_max_ext_len();
1016 }
1017  
1018 sub _strap_bailout_handler
1019 2 ▶{
Subroutine _strap_bailout_handler: called CC=1 SCAR=0.0
1020 2 my ($self, $args) = @_;
1021  
1022 2 die Test::Run::Obj::Error::TestsFail::Bailout->new(
1023 {
1024 bailout_reason => $self->Strap->bailout_reason(),
1025 text => "FOOBAR",
1026 }
1027 );
1028 }
1029  
1030 sub _calc_failed_before_any_test_obj
1031 1 ▶{
Subroutine _calc_failed_before_any_test_obj: called CC=1 SCAR=0.0
1032 1 my $self = shift;
1033  
1034 return $self->_create_failed_obj_instance(
1035 {
1036 (map
1037 2 { $_ => Test::Run::Obj::IntOrUnknown->create_unknown() }
1038 qw(max failed)
1039 ),
1040 canon => "??",
1041 1 (map { $_ => "", } qw(estat wstat)),
1042 percent => undef,
1043 name => $self->_get_last_test_filename(),
1044 },
1045 );
1046 }
1047  
1048 sub _show_results
1049 23 ▶{
Subroutine _show_results: called CC=1 SCAR=0.0
1050 23 my($self) = @_;
1051  
1052 23 $self->_show_success_or_failure();
1053  
1054 15 $self->_report_final_stats();
1055 }
1056  
1057 sub _is_last_test_seen
1058 13 ▶{
Subroutine _is_last_test_seen: called CC=1 SCAR=0.0
1059 13 return shift->last_test_results->seen;
1060 }
1061  
1062 sub _is_test_passing
1063 55 ▶{
Subroutine _is_test_passing: called CC=1 SCAR=0.0
1064 55 my $self = shift;
1065  
1066 55 return $self->last_test_results->passing;
1067 }
1068  
1069 sub _get_failed_and_max_params
1070 12 ▶{
Subroutine _get_failed_and_max_params: called CC=1 SCAR=0.0
1071 12 my $self = shift;
1072  
1073 12 my $last_test = $self->last_test_obj;
1074  
1075 return
1076 [
1077 12 canon => $self->_failed_canon(),
1078 failed => Test::Run::Obj::IntOrUnknown->create_int($last_test->num_failed()),
1079 percent => $last_test->calc_percent(),
1080 ];
1081 }
1082  
1083 # The test program exited with a bad exit status.
1084 sub _dubious_return
1085 6 ▶{
Subroutine _dubious_return: called CC=1 SCAR=0.0
1086 6 my $self = shift;
1087  
1088 6 $self->_report_dubious();
1089  
1090 6 $self->_inc_bad();
1091  
1092 6 return $self->_calc_dubious_return_ret_value();
1093 }
1094  
1095 sub _get_fail_test_scripts_string
1096 7 ▶{
Subroutine _get_fail_test_scripts_string: called CC=1 SCAR=0.0
1097 7 my $self = shift;
1098  
1099 7 return $self->tot->fail_test_scripts_string();
1100 }
1101  
1102 sub _get_undef_tests_params
1103 2 ▶{
Subroutine _get_undef_tests_params: called CC=1 SCAR=0.0
1104 2 my $self = shift;
1105  
1106 return
1107 [
1108 2 canon => "??",
1109 failed => Test::Run::Obj::IntOrUnknown->create_unknown(),
1110 percent => undef,
1111 ];
1112 }
1113  
1114 sub _get_fail_tests_good_percent_string
1115 7 ▶{
Subroutine _get_fail_tests_good_percent_string: called CC=1 SCAR=0.0
1116 7 my $self = shift;
1117  
1118 7 return $self->tot->fail_tests_good_percent_string();
1119 }
1120  
1121 sub _get_FWRS_tests_existence_params
1122 12 ▶{
Subroutine _get_FWRS_tests_existence_params: called CC=2 SCAR=6.9
1123 12 my ($self) = @_;
1124  
1125 return
1126 [
1127 $self->_is_failed_and_max()
1128 10 ? (@{$self->_get_failed_and_max_params()})
1129 12 ▶ : (@{$self->_get_undef_tests_params()})
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_failed_and_max ? : 10 2 12
1130 ]
1131 }
1132  
1133 sub _handle_runtests_error_text
1134 9 ▶{
Subroutine _handle_runtests_error_text: called CC=1 SCAR=0.0
1135 9 my $self = shift;
1136 9 my $args = shift;
1137  
1138 9 my $text = $args->{'text'};
1139  
1140 9 die $text;
1141 }
1142  
1143 sub _is_error_object
1144 9 ▶{
Subroutine _is_error_object: called CC=2 SCAR=7.6
1145 9 my $self = shift;
1146 9 my $error = shift;
1147  
1148 return
1149 (
1150 9 ▶ Scalar::Util::blessed($error) &&
Condition33%1/3
builtin::blessed($error) && $error->isa('Test::Run::Obj::Error::TestsFail')
!ll&&!rl&&r
009
MC/DC0%0/2
builtin::blessed($error) && $error->isa('Test::Run::Obj::Error::TestsFail')
builtin::blessed($error) $error->isa('Test::Run::Obj::Error::TestsFail')
Truth table33%1/3
A && B
A= builtin::blessed($error)B= $error->isa('Test::Run::Obj::Error::TestsFail')
ABresult
0X0
100
111
1151 $error->isa("Test::Run::Obj::Error::TestsFail")
1152 );
1153 }
1154  
1155 sub _get_runtests_error_text
1156 9 ▶{
Subroutine _get_runtests_error_text: called CC=2 SCAR=7.1
1157 9 my $self = shift;
1158 9 my $error = shift;
1159  
1160 return
1161 9 ▶ ($self->_is_error_object($error)
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_error_object($error) ? : 9 0 9
1162 ? $error->stringify()
1163 : $error
1164 );
1165 }
1166  
1167 sub _is_no_tests_run
1168 8 ▶{
Subroutine _is_no_tests_run: called CC=1 SCAR=0.0
1169 8 my $self = shift;
1170  
1171 8 return (! $self->tot->tests());
1172 }
1173  
1174 sub _is_no_tests_output
1175 8 ▶{
Subroutine _is_no_tests_output: called CC=1 SCAR=0.0
1176 8 my $self = shift;
1177  
1178 8 return (! $self->tot->max());
1179 }
1180  
1181 sub _report_success
1182 15 ▶{
Subroutine _report_success: called CC=1 SCAR=0.0
1183 15 my $self = shift;
1184 15 $self->_report(
1185 {
1186 'channel' => "success",
1187 'event' => { 'type' => "success", },
1188 }
1189 );
1190  
1191 15 return;
1192 }
1193  
1194 sub _fail_other_if_bad
1195 7 ▶{
Subroutine _fail_other_if_bad: called CC=2 SCAR=7.4
1196 7 my $self = shift;
1197  
1198 7 ▶ if ($self->tot->bad)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->tot->bad) 7 0 7
1199 {
1200 7 $self->_fail_other_print_bonus_message();
1201 7 $self->_fail_other_throw_exception();
1202 }
1203  
1204 0 return;
1205 }
1206  
1207 sub _calc__fail_other__callbacks
1208 7 ▶{
Subroutine _calc__fail_other__callbacks: called CC=1 SCAR=0.0
1209 7 my $self = shift;
1210  
1211 7 return [qw(
1212 _create_fmts
1213 _fail_other_print_top
1214 _fail_other_print_all_tests
1215 _fail_other_if_bad
1216 )];
1217 }
1218  
1219 sub _fail_other
1220 7 ▶{
Subroutine _fail_other: called CC=1 SCAR=1.2
1221 7 shift->_run_sequence();
1222  
1223 0 return;
1224 }
1225  
1226 sub _show_success_or_failure
1227 23 ▶{
Subroutine _show_success_or_failure: called CC=4 SCAR=14.0
1228 23 my $self = shift;
1229  
1230 23 ▶ if ($self->_all_ok())
Branch: 3 branches
BranchTrueFalseTotal
if ($self->_all_ok) { } 15 8 23
elsif ($self->_is_no_tests_run) { } 0 8 8
elsif ($self->_is_no_tests_output) { } 1 7 8
1231 {
1232 15 return $self->_report_success();
1233 }
1234 elsif ($self->_is_no_tests_run())
1235 {
1236 0 return $self->_fail_no_tests_run();
1237 }
1238 elsif ($self->_is_no_tests_output())
1239 {
1240 1 return $self->_fail_no_tests_output();
1241 }
1242 else
1243 {
1244 7 return $self->_fail_other();
1245 }
1246 }
1247  
1248 sub _handle_runtests_error
1249 9 ▶{
Subroutine _handle_runtests_error: called CC=1 SCAR=0.0
1250 9 my $self = shift;
1251 9 my $args = shift;
1252 9 my $error = $args->{'error'};
1253  
1254 9 $self->_handle_runtests_error_text(
1255 {
1256 'text' => $self->_get_runtests_error_text($error),
1257 },
1258 );
1259 }
1260  
1261 sub _get_canonfailed_params
1262 24 ▶{
Subroutine _get_canonfailed_params: called CC=1 SCAR=0.0
1263 24 my $self = shift;
1264  
1265 24 return [failed => $self->_canonfailed_get_failed(),];
1266 }
1267  
1268 sub _create_canonfailed_obj_instance
1269 24 ▶{
Subroutine _create_canonfailed_obj_instance: called CC=1 SCAR=0.0
1270 24 my ($self, $args) = @_;
1271  
1272 24 return $self->create_pluggable_helper_obj(
1273 {
1274 id => "canon_failed",
1275 args => $args,
1276 }
1277 );
1278 }
1279  
1280 sub _canonfailed_get_canon
1281 24 ▶{
Subroutine _canonfailed_get_canon: called CC=1 SCAR=0.0
1282 24 my ($self) = @_;
1283  
1284 return $self->_create_canonfailed_obj_instance(
1285 {
1286 24 @{$self->_get_canonfailed_params()},
1287 }
1288 );
1289 }
1290  
1291 sub _prepare_for_single_test_run
1292 57 ▶{
Subroutine _prepare_for_single_test_run: called CC=1 SCAR=0.0
1293 57 my ($self, $args) = @_;
1294  
1295 57 $self->_tot_inc('files');
1296  
1297 57 $self->Strap()->_seen_header(0);
1298  
1299 57 $self->_report_single_test_file_start($args);
1300  
1301 57 return;
1302 }
1303  
1304  
1305 sub _calc__run_single_test__callbacks
1306 57 ▶{
Subroutine _calc__run_single_test__callbacks: called CC=1 SCAR=0.0
1307 57 my $self = shift;
1308  
1309 57 return [qw(
1310 _prepare_for_single_test_run
1311 _time_single_test
1312 _calc_test_struct
1313 _process_test_file_results
1314 _recheck_dir_files
1315 )];
1316 }
1317  
1318 sub _run_single_test
1319 57 ▶{
Subroutine _run_single_test: called CC=1 SCAR=0.0
1320 57 my ($self, $args) = @_;
1321  
1322 57 $self->_run_sequence([$args]);
1323  
1324 55 return;
1325 }
1326  
1327 sub _list_tests_as_failures
1328 19 ▶{
Subroutine _list_tests_as_failures: called CC=1 SCAR=0.0
1329 19 my $self = shift;
1330  
1331 return
1332 19 $self->last_test_obj->list_tests_as_failures(
1333 $self->last_test_results->details()
1334 );
1335 }
1336  
1337 sub _process_test_file_results
1338 55 ▶{
Subroutine _process_test_file_results: called CC=2 SCAR=6.9
1339 55 my ($self) = @_;
1340  
1341 55 ▶ if ($self->_is_test_passing())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_test_passing) { } 36 19 55
1342 {
1343 36 $self->_handle_passing_test();
1344 }
1345 else
1346 {
1347 19 $self->_list_tests_as_failures();
1348 19 $self->_add_to_failed_tests();
1349 }
1350  
1351 55 return;
1352 }
1353  
1354 sub _check_for_ok
1355 16 ▶{
Subroutine _check_for_ok: called CC=2 SCAR=7.2
1356 16 my $self = shift;
1357  
1358 16 ▶ assert( ($self->_all_ok() xor keys(%{$self->failed_tests()})),
Condition50%2/4
$self->_all_ok ^^ keys %{$self->failed_tests;}
l&&rl&&!r!l&&r!l&&!r
01501
MC/DC50%1/2
$self->_all_ok ^^ keys %{$self->failed_tests;}
$self->_all_ok keys %{$self->failed_tests;}
Truth table50%2/4
A ^^ B
A= $self->_all_okB= keys %{$self->failed_tests;}
ABresult
110
101
011
000
1359 q{$ok is mutually exclusive with %$failed_tests}
1360 );
1361  
1362 15 return;
1363  
1364 }
1365  
1366 sub _calc_test_file_data_display_path
1367 57 ▶{
Subroutine _calc_test_file_data_display_path: called CC=1 SCAR=0.0
1368 57 my ($self, $idx, $test_file) = @_;
1369  
1370 57 return $test_file;
1371 }
1372  
1373 sub _get_test_file_display_path
1374 174 ▶{
Subroutine _get_test_file_display_path: called CC=1 SCAR=0.0
1375 174 my ($self, $test_file) = @_;
1376  
1377 174 return $self->test_files_data()->{$test_file}->{display_path};
1378 }
1379  
1380 sub _calc_test_file_data_struct
1381 57 ▶{
Subroutine _calc_test_file_data_struct: called CC=1 SCAR=0.0
1382 57 my ($self, $idx, $test_file) = @_;
1383  
1384 return
1385 {
1386 57 idx => $idx,
1387 real_path => $test_file,
1388 display_path => $self->_calc_test_file_data_display_path($idx, $test_file),
1389 };
1390 }
1391  
1392 sub _prepare_test_files_data
1393 51 ▶{
Subroutine _prepare_test_files_data: called CC=2 SCAR=6.9
1394 51 my $self = shift;
1395  
1396 51 foreach my $idx (0 .. $#{$self->test_files()})
1397 {
1398 57 my $test_file = $self->test_files()->[$idx];
1399  
1400 57 $self->test_files_data()->{$test_file} =
1401 $self->_calc_test_file_data_struct($idx, $test_file);
1402 }
1403 }
1404  
1405 sub _calc__real_runtests__callbacks
1406 24 ▶{
Subroutine _calc__real_runtests__callbacks: called CC=1 SCAR=0.0
1407 24 my $self = shift;
1408  
1409 return
1410 24 [qw(
1411 _run_all_tests
1412 _show_results
1413 _check_for_ok
1414 )];
1415 }
1416  
1417 sub _real_runtests
1418 24 ▶{
Subroutine _real_runtests: called CC=1 SCAR=0.0
1419 24 shift->_run_sequence();
1420  
1421 15 return;
1422 }
1423  
1424 sub runtests
1425 24 ▶{
Subroutine runtests: called CC=2 SCAR=6.9
Pod documented
1426 24 my $self = shift;
1427  
1428 24 local ($\, $,);
1429  
1430 24 eval { $self->_real_runtests(@_) };
1431  
1432 24 my $error = $@;
1433  
1434 24 my $ok = $self->_all_ok();
1435  
1436 24 ▶ if ($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) { } 9 15 24
1437 {
1438 9 return $self->_handle_runtests_error(
1439 {
1440 ok => $ok,
1441 error => $error,
1442 }
1443 );
1444 }
1445 else
1446 {
1447 15 return $ok;
1448 }
1449 }
1450  
1451 sub _get_bonusmsg
1452 15 ▶{
Subroutine _get_bonusmsg: called CC=2 SCAR=7.0
1453 15 my $self = shift;
1454  
1455 15 ▶ if (! defined($self->_bonusmsg()))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->_bonusmsg) 15 0 15
1456 {
1457 15 $self->_bonusmsg($self->tot()->get_bonusmsg());
1458 }
1459  
1460 15 return $self->_bonusmsg();
1461 }
1462  
1463 sub _autoflush_file_handles
1464 51 ▶{
Subroutine _autoflush_file_handles: called CC=1 SCAR=0.0
1465 51 my $self = shift;
1466  
1467 51 STDOUT->autoflush(1);
1468 51 STDERR->autoflush(1);
1469 }
1470  
1471 sub _init_failed_tests
1472 51 ▶{
Subroutine _init_failed_tests: called CC=1 SCAR=0.0
1473 51 my $self = shift;
1474  
1475 51 $self->failed_tests({});
1476 }
1477  
1478 sub _prepare_run_all_tests
1479 51 ▶{
Subroutine _prepare_run_all_tests: called CC=1 SCAR=0.0
1480 51 my $self = shift;
1481  
1482 51 $self->_prepare_test_files_data();
1483  
1484 51 $self->_autoflush_file_handles();
1485  
1486 51 $self->_init_failed_tests();
1487  
1488 51 $self->_init_tot();
1489  
1490 51 $self->_init_dir_files();
1491  
1492 51 return;
1493 }
1494  
1495 # FWRS == failed_with_results_seen
1496 sub _get_common_FWRS_params
1497 12 ▶{
Subroutine _get_common_FWRS_params: called CC=1 SCAR=0.0
1498 12 my $self = shift;
1499  
1500 return
1501 [
1502 12 max => Test::Run::Obj::IntOrUnknown->create_int(
1503 $self->last_test_obj->max()
1504 ),
1505 name => $self->_get_last_test_filename(),
1506 estat => "",
1507 wstat => "",
1508 list_len => $self->list_len(),
1509 ];
1510 }
1511  
1512 sub _get_failed_with_results_seen_params
1513 12 ▶{
Subroutine _get_failed_with_results_seen_params: called CC=1 SCAR=0.0
1514 12 my ($self) = @_;
1515  
1516 return
1517 {
1518 12 @{$self->_get_common_FWRS_params()},
1519 12 @{$self->_get_FWRS_tests_existence_params()},
1520 }
1521 }
1522  
1523 sub _failed_with_results_seen
1524 12 ▶{
Subroutine _failed_with_results_seen: called CC=1 SCAR=0.0
1525 12 my $self = shift;
1526  
1527 12 $self->_inc_bad();
1528  
1529 12 $self->_report_failed_with_results_seen();
1530  
1531 return
1532 12 $self->_create_failed_obj_instance(
1533 $self->_get_failed_with_results_seen_params(),
1534 );
1535 }
1536  
1537 sub _get_failed_struct
1538 19 ▶{
Subroutine _get_failed_struct: called CC=3 SCAR=11.0
1539 19 my ($self) = @_;
1540  
1541 19 ▶ if ($self->_get_wstatus())
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_get_wstatus) { } 6 13 19
elsif ($self->_is_last_test_seen) { } 12 1 13
1542 {
1543 6 return $self->_dubious_return();
1544 }
1545 elsif($self->_is_last_test_seen())
1546 {
1547 12 return $self->_failed_with_results_seen();
1548 }
1549 else
1550 {
1551 1 return $self->_failed_before_any_test_output();
1552 }
1553 }
1554  
1555 sub _add_to_failed_tests
1556 19 ▶{
Subroutine _add_to_failed_tests: called CC=1 SCAR=0.0
1557 19 my $self = shift;
1558  
1559 19 $self->failed_tests()->{$self->_get_last_test_filename()} =
1560 $self->_get_failed_struct();
1561  
1562 19 return;
1563 }
1564  
1565 sub _get_last_test_filename
1566 32 ▶{
Subroutine _get_last_test_filename: called CC=1 SCAR=0.0
1567 32 my $self = shift;
1568  
1569 32 return $self->last_test_results->filename();
1570 }
1571  
1572 sub _init_dir_files
1573 51 ▶{
Subroutine _init_dir_files: called CC=2 SCAR=6.9
1574 51 my $self = shift;
1575  
1576 51 ▶ if (defined($self->Leaked_Dir()))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->Leaked_Dir) 2 49 51
1577 {
1578 2 $self->dir_files($self->_get_dir_files());
1579 }
1580 }
1581  
1582 sub _run_all_tests_loop
1583 51 ▶{
Subroutine _run_all_tests_loop: called CC=2 SCAR=6.9
1584 51 my $self = shift;
1585  
1586 51 foreach my $test_file_path (@{$self->test_files()})
1587 {
1588 57 $self->_run_single_test({ test_file => $test_file_path});
1589 }
1590 }
1591  
1592 sub _run_all_tests__run_loop
1593 51 ▶{
Subroutine _run_all_tests__run_loop: called CC=1 SCAR=0.0
1594 51 my $self = shift;
1595  
1596 $self->tot->benchmark_callback(
1597 51 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1598 51 $self->width($self->_leader_width());
1599 51 $self->_run_all_tests_loop();
1600 }
1601 51 );
1602 }
1603  
1604 sub _finalize_run_all_tests
1605 49 ▶{
Subroutine _finalize_run_all_tests: called CC=1 SCAR=0.0
1606 49 my $self = shift;
1607  
1608 49 $self->Strap()->_restore_PERL5LIB();
1609 }
1610  
1611 sub _calc__run_all_tests__callbacks
1612 51 ▶{
Subroutine _calc__run_all_tests__callbacks: called CC=1 SCAR=0.0
1613 51 my $self = shift;
1614  
1615 return
1616 51 [qw(
1617 _prepare_run_all_tests
1618 _run_all_tests__run_loop
1619 _finalize_run_all_tests
1620 )];
1621 }
1622  
1623 51 ▶sub _run_all_tests {
Subroutine _run_all_tests: called CC=1 SCAR=0.0
1624 51 shift->_run_sequence();
1625  
1626 49 return;
1627 }
1628  
1629  
1630 sub _get_dubious_summary_all_subtests_successful
1631 1 ▶{
Subroutine _get_dubious_summary_all_subtests_successful: called CC=1 SCAR=0.0
1632 1 my ($self, $args) = @_;
1633  
1634 1 $self->_report_dubious_summary_all_subtests_successful();
1635  
1636 return
1637 [
1638 1 failed => Test::Run::Obj::IntOrUnknown->zero(),
1639 percent => 0,
1640 canon => "??",
1641 ];
1642 }
1643  
1644 sub _get_no_tests_summary
1645 3 ▶{
Subroutine _get_no_tests_summary: called CC=1 SCAR=0.0
1646 3 my ($self, $args) = @_;
1647  
1648 return
1649 [
1650 3 failed => Test::Run::Obj::IntOrUnknown->create_unknown(),
1651 canon => "??",
1652 percent => undef(),
1653 ];
1654 }
1655  
1656 sub _get_dubious_summary
1657 6 ▶{
Subroutine _get_dubious_summary: called CC=1 SCAR=0.0
1658 6 my ($self, $args) = @_;
1659  
1660 6 my $method = $self->last_test_obj->get_dubious_summary_main_obj_method();
1661  
1662 6 return $self->$method($args);
1663 }
1664  
1665 sub _get_skipped_bonusmsg
1666 0 ▶{
Subroutine _get_skipped_bonusmsg: not called CC=1 SCAR=6.9
1667 0 my $self = shift;
1668  
1669 0 return $self->tot->_get_skipped_bonusmsg();
1670 }
1671  
1672 sub _get_wstatus
1673 25 ▶{
Subroutine _get_wstatus: called CC=1 SCAR=0.0
1674 25 my $self = shift;
1675  
1676 25 return $self->last_test_results->wait;
1677 }
1678  
1679 sub _get_estatus
1680 6 ▶{
Subroutine _get_estatus: called CC=1 SCAR=0.0
1681 6 my $self = shift;
1682  
1683 6 return $self->last_test_results->exit;
1684 }
1685  
1686 sub _get_format_failed_str
1687 15 ▶{
Subroutine _get_format_failed_str: called CC=1 SCAR=0.0
1688 15 my $self = shift;
1689  
1690 15 return "Failed Test";
1691 }
1692  
1693 sub _get_format_failed_str_len
1694 8 ▶{
Subroutine _get_format_failed_str_len: called CC=1 SCAR=0.0
1695 8 my $self = shift;
1696  
1697 8 return length($self->_get_format_failed_str());
1698 }
1699  
1700 sub _get_num_columns
1701 7 ▶{
Subroutine _get_num_columns: called CC=1 SCAR=0.0
1702 7 my $self = shift;
1703  
1704 # Some shells don't handle a full line of text well so we increment
1705 # 1.
1706 7 return ($self->Columns() - 1);
1707 }
1708  
1709 # Find the maximal name length among the failed_tests().
1710 sub _calc_initial_max_namelen
1711 7 ▶{
Subroutine _calc_initial_max_namelen: called CC=3 SCAR=11.0
1712 7 my $self = shift;
1713  
1714 7 my $max = $self->_get_format_failed_str_len();
1715  
1716 7 ▶ while (my ($k, $v) = each(%{$self->failed_tests()}))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$self->failed_tests;}) 7 7 14
1717 {
1718 7 my $l = length($v->{name});
1719  
1720 7 ▶ if ($l > $max)
Branch: 1 branch
BranchTrueFalseTotal
if ($l > $max) 7 0 7
1721 {
1722 7 $max = $l;
1723 }
1724 }
1725  
1726 7 $self->max_namelen($max);
1727  
1728 7 return;
1729 }
1730  
1731 sub _calc_len_subtraction
1732 8 ▶{
Subroutine _calc_len_subtraction: called CC=1 SCAR=0.0
1733 8 my ($self, $field) = @_;
1734  
1735 8 return $self->format_columns()
1736 - $self->_get_fmt_mid_str_len()
1737 - $self->$field()
1738 ;
1739 }
1740  
1741 sub _calc_initial_list_len
1742 7 ▶{
Subroutine _calc_initial_list_len: called CC=1 SCAR=0.0
1743 7 my $self = shift;
1744  
1745 7 $self->format_columns($self->_get_num_columns());
1746  
1747 7 $self->list_len(
1748 $self->_calc_len_subtraction("max_namelen")
1749 );
1750  
1751 7 return;
1752 }
1753  
1754 sub _calc_updated_lens
1755 1 ▶{
Subroutine _calc_updated_lens: called CC=1 SCAR=0.0
1756 1 my $self = shift;
1757  
1758 1 $self->list_len($self->_get_fmt_list_str_len);
1759 1 $self->max_namelen($self->_calc_len_subtraction("list_len"));
1760 }
1761  
1762 sub _calc_more_updated_lens
1763 0 ▶{
Subroutine _calc_more_updated_lens: not called CC=1 SCAR=6.9
1764 0 my $self = shift;
1765  
1766 0 $self->max_namelen($self->_get_format_failed_str_len());
1767  
1768 0 $self->format_columns(
1769 $self->max_namelen()
1770 + $self->_get_fmt_mid_str_len()
1771 + $self->list_len()
1772 );
1773 }
1774  
1775 sub _calc_fmt_list_len
1776 7 ▶{
Subroutine _calc_fmt_list_len: called CC=3 SCAR=11.2
1777 7 my $self = shift;
1778  
1779 7 $self->_calc_initial_list_len();
1780  
1781 7 ▶ if ($self->list_len() < $self->_get_fmt_list_str_len()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->list_len < $self->_get_fmt_list_str_len) 1 6 7
1782 1 $self->_calc_updated_lens();
1783 1 ▶ if ($self->max_namelen() < $self->_get_format_failed_str_len())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->max_namelen < $self->_get_format_failed_str_len) 0 1 1
1784 {
1785 0 $self->_calc_more_updated_lens();
1786 }
1787 }
1788  
1789 7 return;
1790 }
1791  
1792 sub _calc_format_widths
1793 7 ▶{
Subroutine _calc_format_widths: called CC=1 SCAR=0.0
1794 7 my $self = shift;
1795  
1796 7 $self->_calc_initial_max_namelen();
1797  
1798 7 $self->_calc_fmt_list_len();
1799  
1800 7 return;
1801 }
1802  
1803 sub _get_format_middle_str
1804 15 ▶{
Subroutine _get_format_middle_str: called CC=1 SCAR=0.0
1805 15 my $self = shift;
1806  
1807 15 return " Stat Wstat Total Fail Failed ";
1808 }
1809  
1810 sub _get_fmt_mid_str_len
1811 8 ▶{
Subroutine _get_fmt_mid_str_len: called CC=1 SCAR=0.0
1812 8 my $self = shift;
1813  
1814 8 return length($self->_get_format_middle_str());
1815 }
1816  
1817 sub _get_fmt_list_str_len
1818 8 ▶{
Subroutine _get_fmt_list_str_len: called CC=1 SCAR=0.0
1819 8 my $self = shift;
1820  
1821 8 return length($self->_get_format_list_str());
1822 }
1823  
1824 sub _get_format_list_str
1825 15 ▶{
Subroutine _get_format_list_str: called CC=1 SCAR=0.0
1826 15 my $self = shift;
1827  
1828 15 return "List of Failed";
1829 }
1830  
1831 sub _create_fmts
1832 7 ▶{
Subroutine _create_fmts: called CC=1 SCAR=0.0
1833 7 my $self = shift;
1834  
1835 7 $self->_calc_format_widths();
1836  
1837 7 return;
1838 }
1839  
1840 sub _get_fail_other_exception_text
1841 7 ▶{
Subroutine _get_fail_other_exception_text: called CC=1 SCAR=0.0
1842 7 my $self = shift;
1843  
1844 7 return $self->_format_self("fail_other_except");
1845 }
1846  
1847 sub _calc_dubious_return_ret_value
1848 6 ▶{
Subroutine _calc_dubious_return_ret_value: called CC=1 SCAR=0.0
1849 6 my $self = shift;
1850  
1851 6 return $self->_create_failed_obj_instance(
1852 $self->_calc_dubious_return_failed_obj_params(),
1853 );
1854 }
1855  
1856 sub _calc_dubious_return_failed_obj_params
1857 6 ▶{
Subroutine _calc_dubious_return_failed_obj_params: called CC=1 SCAR=0.0
1858 6 my $self = shift;
1859  
1860 return
1861 {
1862 6 @{$self->_get_dubious_summary()},
1863 6 @{$self->last_test_obj->get_failed_obj_params()},
1864 6 @{$self->last_test_results->get_failed_obj_params()},
1865 };
1866 }
1867  
1868 =head2 $self->_report_failed_before_any_test_output();
1869  
1870 [This is a method that needs to be over-rided.]
1871  
1872 =cut
1873  
1874 =head2 $self->_report_skipped_test()
1875  
1876 [This is a method that needs to be over-rided.]
1877  
1878 Should report the skipped test.
1879  
1880 =cut
1881  
1882 =head2 $self->_report_all_ok_test()
1883  
1884 [This is a method that needs to be over-rided.]
1885  
1886 Should report the all OK test.
1887  
1888 =cut
1889  
1890 =head2 $self->_report_all_skipped_test()
1891  
1892 [This is a method that needs to be over-rided.]
1893  
1894 Should report the all-skipped test.
1895  
1896 =cut
1897  
1898 =head2 $self->_report_single_test_file_start({test_file => "t/my_test_file.t"})
1899  
1900 [This is a method that needs to be over-rided.]
1901  
1902 Should start the report for the C<test_file> file.
1903  
1904 =cut
1905  
1906 =head2 $self->_report('channel' => $channel, 'event' => $event_handle);
1907  
1908 [This is a method that needs to be over-rided.]
1909  
1910 Reports the C<$event_handle> event to channel C<$channel>. This should be
1911 overrided by derived classes to do alternate functionality besides calling
1912 output()->print_message(), also different based on the channel.
1913  
1914 Currently available channels are:
1915  
1916 =over 4
1917  
1918 =item 'success'
1919  
1920 The success report.
1921  
1922 =back
1923  
1924 An event is a hash ref that should contain a 'type' property. Currently
1925 supported types are:
1926  
1927 =over 4
1928  
1929 =item * success
1930  
1931 A success type.
1932  
1933 =back
1934  
1935 =cut
1936  
1937 =head2 $self->_report_final_stats()
1938  
1939 [This is a method that needs to be over-rided.]
1940  
1941 Reports the final statistics.
1942  
1943 =cut
1944  
1945 =head2 $self->_fail_other_print_top()
1946  
1947 [This is a method that needs to be over-rided.]
1948  
1949 Prints the header of the files that failed.
1950  
1951 =cut
1952  
1953 =head2 $self->_fail_other_report_test($script_name)
1954  
1955 [This is a method that needs to be over-rided.]
1956  
1957 In case of failure from a different reason - report that test script.
1958 Test::Run iterates over all the scripts and reports them one by one.
1959  
1960 =cut
1961  
1962  
1963 =head2 $self->_fail_other_print_bonus_message()
1964  
1965 [This is a method that needs to be over-rided.]
1966  
1967 Should report the bonus message in case of failure from a different
1968 reason.
1969  
1970 =cut
1971  
1972 =head2 $self->_report_tap_event($args)
1973  
1974 [This is a method that needs to be over-rided.]
1975  
1976 =head2 $self->_report_script_start_environment()
1977  
1978 [This is a method that needs to be over-rided.]
1979  
1980 Should report the environment of the script at its beginning.
1981  
1982 =head2 $self->_handle_test_file_opening_error($args)
1983  
1984 [This is a method that needs to be over-rided.]
1985  
1986 Should handle the case where the test file cannot be opened.
1987  
1988 =cut
1989  
1990 =head2 $self->_report_test_progress($args)
1991  
1992 [This is a method that needs to be over-rided.]
1993  
1994 Report the text progress. In the command line it would be a ok $curr/$total
1995 or NOK.
1996  
1997 =cut
1998 =head2 The common test-context $args param
1999  
2000 Contains:
2001  
2002 =over 4
2003  
2004 =item 'test_struct' => $test
2005  
2006 A reference to the test summary object.
2007  
2008 =item estatus
2009  
2010 The exit status of the test file.
2011  
2012 =back
2013  
2014 =head2 $test_run->_report_dubious($args)
2015  
2016 [This is a method that needs to be over-rided.]
2017  
2018 Is called to report the "dubious" error, when the test returns a non-true
2019 error code.
2020  
2021 $args are the test-context - see above.
2022  
2023 =cut
2024  
2025 =head2 $test_run->_report_dubious_summary_all_subtests_successful($args)
2026  
2027 [This is a method that needs to be over-rided.]
2028  
2029 $args are the test-context - see above.
2030  
2031 =head2 $test_run->_report_premature_test_dubious_summary($args)
2032  
2033 [This is a method that needs to be over-rided.]
2034  
2035 $args are the test-context - see above.
2036  
2037 =head2 opendir
2038  
2039 This method is placed in the namespace by Fatal.pm. This entry is here just
2040 to settle Pod::Coverage.
2041  
2042 =cut
2043  
2044 15 1;
2045  
2046 =head1 AUTHOR
2047  
2048 Test::Run::Core is based on L<Test::Harness>, and has later been spinned off
2049 as a separate module.
2050  
2051 =head2 Test:Harness Authors
2052  
2053 Either Tim Bunce or Andreas Koenig, we don't know. What we know for
2054 sure is, that it was inspired by Larry Wall's TEST script that came
2055 with perl distributions for ages. Numerous anonymous contributors
2056 exist. Andreas Koenig held the torch for many years, and then
2057 Michael G Schwern.
2058  
2059 Test::Harness was then maintained by Andy Lester C<< <andy at petdance.com> >>.
2060  
2061 =head2 Test::Run::Obj Authors
2062  
2063 Shlomi Fish, L<http://www.shlomifish.org/> .
2064  
2065 Note: this file is a rewrite of the original Test::Run code in order to
2066 change to a more liberal license.
2067  
2068 =head1 LICENSE
2069  
2070 This file is licensed under the MIT License:
2071  
2072 http://www.opensource.org/licenses/mit-license.php
2073  
2074 =cut
« Run/Obj/TotObj.pm ↑ Summary Run/Base.pm »