Run/Obj/TestObj.pm

filter: Statementstmt 98.5% 68 / 69 Branchbran 90.0% 9 / 10 Conditioncond 91.6% 11 / 12 MC/DCmcdc 87.5% 7 / 8 Subroutinesub 100% 22 / 22 Podpod 100% 12 / 12 totaltotal 96.9% 129 / 133 CC 10 SCAR 5.4
CC
10
Cov
97%
get_reason
3.0
get_dubious_summary_main_obj_method
3.0
_calc_tests_as_failures
2.1
CRAP 1.7
« Run/Straps.pm ↑ Summary Run/Plugin/CmdLine/Output.pm »
1 package Test::Run::Obj::TestObj;
2  
3 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 Test::Run::Obj::TestObj - results of a single test script.
9  
10 =cut
11  
12 9 ▶use vars qw(@fields);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 9 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 9 extends('Test::Run::Base::Struct');
17  
18 9 ▶use MRO::Compat;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 9 ▶use Test::Run::Obj::IntOrUnknown;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 =head1 FIELDS
23  
24 =head2 $self->bonus()
25  
26 Number of TODO tests that unexpectedly passed.
27  
28 =head2 $self->failed()
29  
30 Returns an array reference containing list of test numbers that failed.
31  
32 =head2 $self->ok()
33  
34 Number of tests that passed.
35  
36 =head2 $self->next()
37  
38 The next expected event.
39  
40 =head2 $self->max()
41  
42 The number of plannedt tests.
43  
44 =head2 $self->skipped()
45  
46 The number of skipped tests.
47  
48 =head2 $self->skip_all()
49  
50 This field will contain the reason for why the entire test script was skipped,
51 in cases when it was.
52  
53 =head2 $self->skip_reason()
54  
55 The skip reason for the last skipped test that specified such a reason.
56  
57 =cut
58  
59 9 has 'bonus' => (is => "rw", isa => "Num");
60 9 has 'failed' => (is => "rw", isa => "ArrayRef");
61 9 has 'max' => (is => "rw", isa => "Num");
62 9 has 'ml' => (is => "rw", isa => "Str");
63 9 has 'next' => (is => "rw", isa => "Num");
64 9 has 'ok' => (is => "rw", isa => "Num");
65 9 has 'skip_all' => (is => "rw", isa => "Maybe[Str]");
66 9 has 'skipped' => (is => "rw", isa => "Num");
67 9 has 'skip_reason' => (is => "rw", isa => "Maybe[Str]");
68  
69 =head2 BUILD
70  
71 For Moose.
72  
73 =cut
74  
75 sub BUILD
76 55 ▶{
Subroutine BUILD: called CC=1 SCAR=0.0
Pod documented
77 55 my $self = shift;
78  
79 55 $self->_register_obj_formatter(
80 {
81 name => "dont_know_which_tests_failed",
82 format => "Don't know which tests failed: got %(ok)s ok, expected %(max)s",
83 },
84 );
85  
86 55 return;
87 }
88  
89 =head2 $self->add_to_failed(@failures)
90  
91 Add failures to the failed() slot.
92  
93 =cut
94  
95 sub add_to_failed
96 21 ▶{
Subroutine add_to_failed: called CC=1 SCAR=0.0
Pod documented
97 21 my $self = shift;
98 21 push @{$self->failed()}, @_;
99 }
100  
101 sub _get_reason_default
102 1 ▶{
Subroutine _get_reason_default: called CC=1 SCAR=0.0
103 1 return "no reason given";
104 }
105  
106 =head2 $self->get_reason()
107  
108 Gets the reason or defaults to the default.
109  
110 =cut
111  
112 sub get_reason
113 3 ▶{
Subroutine get_reason: called CC=3 SCAR=11.1
Pod documented
114 3 my $self = shift;
115  
116 return
117 3 ▶ +(defined($self->skip_all()) && length($self->skip_all())) ?
Branch: 1 branch
BranchTrueFalseTotal
defined $self->skip_all && length $self->skip_all ? : 2 1 3
Condition66%2/3
defined $self->skip_all and length $self->skip_all
!ll&&!rl&&r
012
MC/DC50%1/2
defined $self->skip_all and length $self->skip_all
defined $self->skip_all length $self->skip_all
Truth table66%2/3
A and B
A= defined $self->skip_allB= length $self->skip_all
ABresult
0X0
100
111
118 $self->skip_all() :
119 $self->_get_reason_default()
120 ;
121 }
122  
123 =head2 $self->num_failed()
124  
125 Returns the number of failed tests.
126  
127 =cut
128  
129 sub num_failed
130 24 ▶{
Subroutine num_failed: called CC=1 SCAR=0.0
Pod documented
131 24 my $self = shift;
132  
133 24 return scalar(@{$self->failed()});
134 }
135  
136 =head2 $self->calc_percent()
137  
138 Calculates the percent of failed tests.
139  
140 =cut
141  
142 sub calc_percent
143 12 ▶{
Subroutine calc_percent: called CC=1 SCAR=0.0
Pod documented
144 12 my $self = shift;
145  
146 12 return ( (100*$self->num_failed()) / $self->max() );
147 }
148  
149 =head2 $self->add_next_to_failed()
150  
151 Adds the tests from ->next() to ->max() to the list of failed tests.
152  
153 =cut
154  
155 sub add_next_to_failed
156 2 ▶{
Subroutine add_next_to_failed: called CC=1 SCAR=0.0
Pod documented
157 2 my $self = shift;
158  
159 2 return $self->add_to_failed($self->next() .. $self->max());
160 }
161  
162 =head2 $self->is_failed_and_max()
163  
164 Returns if there are failed tests B<and> the maximal test number was set.
165  
166 =cut
167  
168 sub is_failed_and_max
169 24 ▶{
Subroutine is_failed_and_max: called CC=2 SCAR=6.9
Pod documented
170 24 my $self = shift;
171  
172 24 ▶ return scalar(@{$self->failed()}) && $self->max();
Condition100%3/3
scalar @{$self->failed;} && $self->max
!ll&&!rl&&r
2220
MC/DC100%2/2
scalar @{$self->failed;} && $self->max
scalar @{$self->failed;} $self->max
Truth table100%3/3
A && B
A= scalar @{$self->failed;}B= $self->max
ABresult
0X0
100
111
173 }
174  
175 sub _get_dont_know_which_tests_failed_msg
176 2 ▶{
Subroutine _get_dont_know_which_tests_failed_msg: called CC=1 SCAR=0.0
177 2 my $self = shift;
178  
179 2 return $self->_format_self("dont_know_which_tests_failed");
180 }
181  
182 =head2 $self->skipped_or_bonus()
183  
184 Returns whether the test file is either skipped() or bonus().
185  
186 =cut
187  
188 sub skipped_or_bonus
189 33 ▶{
Subroutine skipped_or_bonus: called CC=2 SCAR=6.9
Pod documented
190 33 my $self = shift;
191  
192 33 ▶ return $self->skipped() || $self->bonus();
Condition100%3/3
$self->skipped || $self->bonus
l!l&&r!l&&!r
5622
MC/DC100%2/2
$self->skipped || $self->bonus
$self->skipped $self->bonus
Truth table100%3/3
A || B
A= $self->skippedB= $self->bonus
ABresult
1X1
011
000
193 }
194  
195 =head2 $self->all_succesful()
196  
197 A predicate that calculates if all the tests in the TestObj were successful.
198  
199 =cut
200  
201 sub all_succesful
202 3 ▶{
Subroutine all_succesful: called CC=2 SCAR=6.9
Pod documented
203 3 my $self = shift;
204  
205 return
206 (
207 ($self->next() == $self->max() + 1)
208 &&
209 3 ▶ (! @{$self->failed()})
Condition100%3/3
$self->next == $self->max + 1 && !@{$self->failed;}
!ll&&!rl&&r
111
MC/DC100%2/2
$self->next == $self->max + 1 && !@{$self->failed;}
$self->next == $self->max + 1 !@{$self->failed;}
Truth table100%3/3
A && not(B)
A= $self->next == $self->max + 1B= !@{$self->failed;}
ABresult
0X0
100
111
210 );
211 }
212  
213 =head2 $self->get_dubious_summary_main_obj_method()
214  
215 Returns the method name of the main object that should be propagated
216 based on the success/failure status of this test object.
217  
218 =cut
219  
220 sub get_dubious_summary_main_obj_method
221 6 ▶{
Subroutine get_dubious_summary_main_obj_method: called CC=3 SCAR=11.0
Pod documented
222 6 my $self = shift;
223  
224 return
225 6 ▶ $self->max()
Branch: 2 branches
BranchTrueFalseTotal
$self->max ? : 3 3 6
$self->all_succesful ? : 1 2 3
226 ? ($self->all_succesful()
227 ? "_get_dubious_summary_all_subtests_successful"
228 : "_get_premature_test_dubious_summary"
229 )
230 : "_get_no_tests_summary"
231 ;
232 }
233  
234 =head2 $self->get_failed_obj_params
235  
236 Returns a key value array ref of params for initializing the failed-object.
237  
238 =cut
239  
240 sub get_failed_obj_params
241 6 ▶{
Subroutine get_failed_obj_params: called CC=2 SCAR=6.9
Pod documented
242 6 my $self = shift;
243  
244 return
245 [
246 6 ▶ max => ($self->max()
Branch: 1 branch
BranchTrueFalseTotal
$self->max ? : 3 3 6
247 ? Test::Run::Obj::IntOrUnknown->create_int($self->max())
248 : Test::Run::Obj::IntOrUnknown->create_unknown()
249 ),
250 ];
251 }
252  
253 sub _still_running
254 19 ▶{
Subroutine _still_running: called CC=1 SCAR=0.0
255 19 my $self = shift;
256  
257 19 return ($self->next() <= $self->max());
258 }
259  
260  
261 sub _calc_tests_as_failures
262 19 ▶{
Subroutine _calc_tests_as_failures: called CC=2 SCAR=7.4
263 19 my ($self, $details) = @_;
264  
265 19 ▶ if ($self->_still_running())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_still_running) { } 0 19 19
266 {
267 0 return [$self->next() .. $self->max()];
268 }
269 else
270 {
271 return
272 [
273 19 grep { ref($details->[$_-1]) }
274 (($self->max()+1) .. @$details)
275 ];
276 }
277 }
278  
279 =head2 $self->list_tests_as_failures($last_test_results->details())
280  
281 Lists the tests as failures where appropriate.
282  
283 =cut
284  
285 sub list_tests_as_failures
286 19 ▶{
Subroutine list_tests_as_failures: called CC=1 SCAR=0.0
Pod documented
287 19 my ($self, $details) = @_;
288  
289 19 $self->add_to_failed(@{$self->_calc_tests_as_failures($details)});
290 }
291  
292 9 1;
293  
294 __END__
« Run/Straps.pm ↑ Summary Run/Plugin/CmdLine/Output.pm »