1 package TAP::Parser::Result::Test;
5 use vars qw($VERSION @ISA);
6 use TAP::Parser::Result;
7 @ISA = 'TAP::Parser::Result';
13 TAP::Parser::Result::Test - Test result token.
25 This is a subclass of L<TAP::Parser::Result>. A token of this class will be
26 returned if a test line is encountered.
31 =head1 OVERRIDDEN METHODS
33 This class is the workhorse of the L<TAP::Parser> system. Most TAP lines will
34 be test lines and if C<< $result->is_test >>, then you have a bunch of methods
37 =head2 Instance Methods
41 ##############################################################################
47 Returns the literal text of the C<ok> or C<not ok> status.
51 sub ok { shift->{ok} }
53 ##############################################################################
57 my $test_number = $result->number;
59 Returns the number of the test, even if the original TAP output did not supply
64 sub number { shift->{test_num} }
67 my ( $self, $number ) = @_;
68 $self->{test_num} = $number;
71 ##############################################################################
75 my $description = $result->description;
77 Returns the description of the test, if any. This is the portion after the
78 test number but before the directive.
82 sub description { shift->{description} }
84 ##############################################################################
88 my $directive = $result->directive;
90 Returns either C<TODO> or C<SKIP> if either directive was present for a test
95 sub directive { shift->{directive} }
97 ##############################################################################
101 my $explanation = $result->explanation;
103 If a test had either a C<TODO> or C<SKIP> directive, this method will return
104 the accompanying explantion, if present.
106 not ok 17 - 'Pigs can fly' # TODO not enough acid
108 For the above line, the explanation is I<not enough acid>.
112 sub explanation { shift->{explanation} }
114 ##############################################################################
118 if ( $result->is_ok ) { ... }
120 Returns a boolean value indicating whether or not the test passed. Remember
121 that for TODO tests, the test always passes.
123 If the test is unplanned, this method will always return false. See
131 return if $self->is_unplanned;
133 # TODO directives reverse the sense of a test.
134 return $self->has_todo ? 1 : $self->ok !~ /not/;
137 ##############################################################################
139 =head3 C<is_actual_ok>
141 if ( $result->is_actual_ok ) { ... }
143 Returns a boolean value indicating whether or not the test passed, regardless
150 return $self->{ok} !~ /not/;
153 ##############################################################################
155 =head3 C<actual_passed>
157 Deprecated. Please use C<is_actual_ok> instead.
162 warn 'actual_passed() is deprecated. Please use "is_actual_ok()"';
166 ##############################################################################
168 =head3 C<todo_passed>
170 if ( $test->todo_passed ) {
171 # test unexpectedly succeeded
174 If this is a TODO test and an 'ok' line, this method returns true.
175 Otherwise, it will always return false (regardless of passing status on
178 This is used to track which tests unexpectedly succeeded.
184 return $self->has_todo && $self->is_actual_ok;
187 ##############################################################################
189 =head3 C<todo_failed>
191 # deprecated in favor of 'todo_passed'. This method was horribly misnamed.
193 This was a badly misnamed method. It indicates which TODO tests unexpectedly
194 succeeded. Will now issue a warning and call C<todo_passed>.
199 warn 'todo_failed() is deprecated. Please use "todo_passed()"';
203 ##############################################################################
207 if ( $result->has_skip ) { ... }
209 Returns a boolean value indicating whether or not this test has a SKIP
214 if ( $result->has_todo ) { ... }
216 Returns a boolean value indicating whether or not this test has a TODO
221 print $result->as_string;
223 This method prints the test as a string. It will probably be similar, but
224 not necessarily identical, to the original test line. Directives are
225 capitalized, some whitespace may be trimmed and a test number will be added if
226 it was not present in the original line. If you need the original text of the
227 test line, use the C<raw> method.
233 my $string = $self->ok . " " . $self->number;
234 if ( my $description = $self->description ) {
235 $string .= " $description";
237 if ( my $directive = $self->directive ) {
238 my $explanation = $self->explanation;
239 $string .= " # $directive $explanation";
244 ##############################################################################
246 =head3 C<is_unplanned>
248 if ( $test->is_unplanned ) { ... }
249 $test->is_unplanned(1);
251 If a test number is greater than the number of planned tests, this method will
252 return true. Unplanned tests will I<always> return false for C<is_ok>,
253 regardless of whether or not the test C<has_todo>.
255 Note that if tests have a trailing plan, it is not possible to set this
256 property for unplanned tests as we do not know it's unplanned until the plan
269 return ( $self->{unplanned} || '' ) unless @_;
270 $self->{unplanned} = !!shift;