blib/lib/TAP/Parser/Result/Test.pm

filter: Statementstmt 100% 41 / 41 Branchbran 100% 10 / 10 Conditioncond 100% 5 / 5 MC/DCmcdc 100% 3 / 3 Subroutinesub 100% 16 / 16 Podpod 100% 12 / 12 totaltotal 100% 87 / 87 CC 8 SCAR 6.3
CC
8
Cov
100%
is_ok
3.0
as_string
3.0
is_unplanned
3.0
CRAP 1.9
« blib/lib/App/Prove/State/Result/Test.pm ↑ Summary blib/lib/TAP/Parser/Result.pm »
1 package TAP::Parser::Result::Test;
2  
3 32 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 32 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 32 ▶use base 'TAP::Parser::Result';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 TAP::Parser::Result::Test - Test result token.
11  
12 =head1 VERSION
13  
14 Version 3.52
15  
16 =cut
17  
18 32 our $VERSION = '3.52';
19  
20 =head1 DESCRIPTION
21  
22 This is a subclass of L<TAP::Parser::Result>. A token of this class will be
23 returned if a test line is encountered.
24  
25 1..1
26 ok 1 - woo hooo!
27  
28 =head1 OVERRIDDEN METHODS
29  
30 This class is the workhorse of the L<TAP::Parser> system. Most TAP lines will
31 be test lines and if C<< $result->is_test >>, then you have a bunch of methods
32 at your disposal.
33  
34 =head2 Instance Methods
35  
36 =cut
37  
38 ##############################################################################
39  
40 =head3 C<ok>
41  
42 my $ok = $result->ok;
43  
44 Returns the literal text of the C<ok> or C<not ok> status.
45  
46 =cut
47  
48 13595 ▶sub ok { shift->{ok} }
Subroutine ok: called CC=1 SCAR=0.0
Pod documented
49  
50 ##############################################################################
51  
52 =head3 C<number>
53  
54 my $test_number = $result->number;
55  
56 Returns the number of the test, even if the original TAP output did not supply
57 that number.
58  
59 =cut
60  
61 13418 ▶sub number { shift->{test_num} }
Subroutine number: called CC=1 SCAR=0.0
Pod documented
62  
63 52 ▶sub _number {
Subroutine _number: called CC=1 SCAR=0.0
64 52 my ( $self, $number ) = @_;
65 52 $self->{test_num} = $number;
66 }
67  
68 ##############################################################################
69  
70 =head3 C<description>
71  
72 my $description = $result->description;
73  
74 Returns the description of the test, if any. This is the portion after the
75 test number but before the directive.
76  
77 =cut
78  
79 770 ▶sub description { shift->{description} }
Subroutine description: called CC=1 SCAR=0.0
Pod documented
80  
81 ##############################################################################
82  
83 =head3 C<directive>
84  
85 my $directive = $result->directive;
86  
87 Returns either C<TODO> or C<SKIP> if either directive was present for a test
88 line.
89  
90 =cut
91  
92 42 ▶sub directive { shift->{directive} }
Subroutine directive: called CC=1 SCAR=0.0
Pod documented
93  
94 ##############################################################################
95  
96 =head3 C<explanation>
97  
98 my $explanation = $result->explanation;
99  
100 If a test had either a C<TODO> or C<SKIP> directive, this method will return
101 the accompanying explanation, if present.
102  
103 not ok 17 - 'Pigs can fly' # TODO not enough acid
104  
105 For the above line, the explanation is I<not enough acid>.
106  
107 =cut
108  
109 188 ▶sub explanation { shift->{explanation} }
Subroutine explanation: called CC=1 SCAR=0.0
Pod documented
110  
111 ##############################################################################
112  
113 =head3 C<is_ok>
114  
115 if ( $result->is_ok ) { ... }
116  
117 Returns a boolean value indicating whether or not the test passed. Remember
118 that for TODO tests, the test always passes.
119  
120 If the test is unplanned, this method will always return false. See
121 C<is_unplanned>.
122  
123 =cut
124  
125 13752 ▶sub is_ok {
Subroutine is_ok: called CC=3 SCAR=11.0
Pod documented
126 13752 my $self = shift;
127  
128 13752 ▶ return if $self->is_unplanned;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_unplanned 114 13638 13752
129  
130 # TODO directives reverse the sense of a test.
131 13638 ▶ return $self->has_todo ? 1 : $self->ok !~ /not/;
Branch: 1 branch
BranchTrueFalseTotal
$self->has_todo ? : 85 13553 13638
132 }
133  
134 ##############################################################################
135  
136 =head3 C<is_actual_ok>
137  
138 if ( $result->is_actual_ok ) { ... }
139  
140 Returns a boolean value indicating whether or not the test passed, regardless
141 of its TODO status.
142  
143 =cut
144  
145 13799 ▶sub is_actual_ok {
Subroutine is_actual_ok: called CC=1 SCAR=0.0
Pod documented
146 13799 my $self = shift;
147 13799 return $self->{ok} !~ /not/;
148 }
149  
150 ##############################################################################
151  
152 =head3 C<actual_passed>
153  
154 Deprecated. Please use C<is_actual_ok> instead.
155  
156 =cut
157  
158 351 ▶sub actual_passed {
Subroutine actual_passed: called CC=1 SCAR=0.0
Pod documented
159 351 warn 'actual_passed() is deprecated. Please use "is_actual_ok()"';
160 351 goto &is_actual_ok;
161 }
162  
163 ##############################################################################
164  
165 =head3 C<todo_passed>
166  
167 if ( $test->todo_passed ) {
168 # test unexpectedly succeeded
169 }
170  
171 If this is a TODO test and an 'ok' line, this method returns true.
172 Otherwise, it will always return false (regardless of passing status on
173 non-todo tests).
174  
175 This is used to track which tests unexpectedly succeeded.
176  
177 =cut
178  
179 13032 ▶sub todo_passed {
Subroutine todo_passed: called CC=2 SCAR=6.9
Pod documented
180 13032 my $self = shift;
181 13032 ▶ return $self->has_todo && $self->is_actual_ok;
Condition100%3/3
$self->has_todo && $self->is_actual_ok
!ll&&!rl&&r
129724317
MC/DC100%2/2
$self->has_todo && $self->is_actual_ok
$self->has_todo $self->is_actual_ok
Truth table100%3/3
A && B
A= $self->has_todoB= $self->is_actual_ok
ABresult
0X0
100
111
182 }
183  
184 ##############################################################################
185  
186 =head3 C<todo_failed>
187  
188 # deprecated in favor of 'todo_passed'. This method was horribly misnamed.
189  
190 This was a badly misnamed method. It indicates which TODO tests unexpectedly
191 succeeded. Will now issue a warning and call C<todo_passed>.
192  
193 =cut
194  
195 1 ▶sub todo_failed {
Subroutine todo_failed: called CC=1 SCAR=0.0
Pod documented
196 1 warn 'todo_failed() is deprecated. Please use "todo_passed()"';
197 1 goto &todo_passed;
198 }
199  
200 ##############################################################################
201  
202 =head3 C<has_skip>
203  
204 if ( $result->has_skip ) { ... }
205  
206 Returns a boolean value indicating whether or not this test has a SKIP
207 directive.
208  
209 =head3 C<has_todo>
210  
211 if ( $result->has_todo ) { ... }
212  
213 Returns a boolean value indicating whether or not this test has a TODO
214 directive.
215  
216 =head3 C<as_string>
217  
218 print $result->as_string;
219  
220 This method prints the test as a string. It will probably be similar, but
221 not necessarily identical, to the original test line. Directives are
222 capitalized, some whitespace may be trimmed and a test number will be added if
223 it was not present in the original line. If you need the original text of the
224 test line, use the C<raw> method.
225  
226 =cut
227  
228 31 ▶sub as_string {
Subroutine as_string: called CC=3 SCAR=11.0
Pod documented
229 31 my $self = shift;
230 31 my $string = $self->ok . " " . $self->number;
231 31 ▶ if ( my $description = $self->description ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $description = $self->description) 26 5 31
232 26 $string .= " $description";
233 }
234 31 ▶ if ( my $directive = $self->directive ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $directive = $self->directive) 13 18 31
235 13 my $explanation = $self->explanation;
236 13 $string .= " # $directive $explanation";
237 }
238 31 return $string;
239 }
240  
241 ##############################################################################
242  
243 =head3 C<is_unplanned>
244  
245 if ( $test->is_unplanned ) { ... }
246 $test->is_unplanned(1);
247  
248 If a test number is greater than the number of planned tests, this method will
249 return true. Unplanned tests will I<always> return false for C<is_ok>,
250 regardless of whether or not the test C<has_todo>.
251  
252 Note that if tests have a trailing plan, it is not possible to set this
253 property for unplanned tests as we do not know it's unplanned until the plan
254 is reached:
255  
256 print <<'END';
257 ok 1
258 ok 2
259 1..1
260 END
261  
262 =cut
263  
264 13880 ▶sub is_unplanned {
Subroutine is_unplanned: called CC=3 SCAR=11.0
Pod documented
265 13880 my $self = shift;
266 13880 ▶ return ( $self->{unplanned} || '' ) unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 13830 50 13880
Condition100%2/2
$self->{'unplanned'} || ''
l!l
12413706
MC/DC100%1/1
$self->{'unplanned'} || ''
$self->{'unplanned'}
Truth table100%2/2
A
A= $self->{'unplanned'}
Aresult
11
00
267 50 $self->{unplanned} = !!shift;
268 50 return $self;
269 }
270  
271 32 1;
« blib/lib/App/Prove/State/Result/Test.pm ↑ Summary blib/lib/TAP/Parser/Result.pm »