<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package TAP::Parser::Result::Test;

use strict;
use warnings;

use base 'TAP::Parser::Result';

=head1 NAME

TAP::Parser::Result::Test - Test result token.

=head1 VERSION

Version 3.42

=cut

our $VERSION = '3.42';

=head1 DESCRIPTION

This is a subclass of L&lt;TAP::Parser::Result&gt;.  A token of this class will be
returned if a test line is encountered.

 1..1
 ok 1 - woo hooo!

=head1 OVERRIDDEN METHODS

This class is the workhorse of the L&lt;TAP::Parser&gt; system.  Most TAP lines will
be test lines and if C&lt;&lt; $result-&gt;is_test &gt;&gt;, then you have a bunch of methods
at your disposal.

=head2 Instance Methods

=cut

##############################################################################

=head3 C&lt;ok&gt;

  my $ok = $result-&gt;ok;

Returns the literal text of the C&lt;ok&gt; or C&lt;not ok&gt; status.

=cut

sub ok { shift-&gt;{ok} }

##############################################################################

=head3 C&lt;number&gt;

  my $test_number = $result-&gt;number;

Returns the number of the test, even if the original TAP output did not supply
that number.

=cut

sub number { shift-&gt;{test_num} }

sub _number {
    my ( $self, $number ) = @_;
    $self-&gt;{test_num} = $number;
}

##############################################################################

=head3 C&lt;description&gt;

  my $description = $result-&gt;description;

Returns the description of the test, if any.  This is the portion after the
test number but before the directive.

=cut

sub description { shift-&gt;{description} }

##############################################################################

=head3 C&lt;directive&gt;

  my $directive = $result-&gt;directive;

Returns either C&lt;TODO&gt; or C&lt;SKIP&gt; if either directive was present for a test
line.

=cut

sub directive { shift-&gt;{directive} }

##############################################################################

=head3 C&lt;explanation&gt;

  my $explanation = $result-&gt;explanation;

If a test had either a C&lt;TODO&gt; or C&lt;SKIP&gt; directive, this method will return
the accompanying explanation, if present.

  not ok 17 - 'Pigs can fly' # TODO not enough acid

For the above line, the explanation is I&lt;not enough acid&gt;.

=cut

sub explanation { shift-&gt;{explanation} }

##############################################################################

=head3 C&lt;is_ok&gt;

  if ( $result-&gt;is_ok ) { ... }

Returns a boolean value indicating whether or not the test passed.  Remember
that for TODO tests, the test always passes.

If the test is unplanned, this method will always return false.  See
C&lt;is_unplanned&gt;.

=cut

sub is_ok {
    my $self = shift;

    return if $self-&gt;is_unplanned;

    # TODO directives reverse the sense of a test.
    return $self-&gt;has_todo ? 1 : $self-&gt;ok !~ /not/;
}

##############################################################################

=head3 C&lt;is_actual_ok&gt;

  if ( $result-&gt;is_actual_ok ) { ... }

Returns a boolean value indicating whether or not the test passed, regardless
of its TODO status.

=cut

sub is_actual_ok {
    my $self = shift;
    return $self-&gt;{ok} !~ /not/;
}

##############################################################################

=head3 C&lt;actual_passed&gt;

Deprecated.  Please use C&lt;is_actual_ok&gt; instead.

=cut

sub actual_passed {
    warn 'actual_passed() is deprecated.  Please use "is_actual_ok()"';
    goto &amp;is_actual_ok;
}

##############################################################################

=head3 C&lt;todo_passed&gt;

  if ( $test-&gt;todo_passed ) {
     # test unexpectedly succeeded
  }

If this is a TODO test and an 'ok' line, this method returns true.
Otherwise, it will always return false (regardless of passing status on
non-todo tests).

This is used to track which tests unexpectedly succeeded.

=cut

sub todo_passed {
    my $self = shift;
    return $self-&gt;has_todo &amp;&amp; $self-&gt;is_actual_ok;
}

##############################################################################

=head3 C&lt;todo_failed&gt;

  # deprecated in favor of 'todo_passed'.  This method was horribly misnamed.

This was a badly misnamed method.  It indicates which TODO tests unexpectedly
succeeded.  Will now issue a warning and call C&lt;todo_passed&gt;.

=cut

sub todo_failed {
    warn 'todo_failed() is deprecated.  Please use "todo_passed()"';
    goto &amp;todo_passed;
}

##############################################################################

=head3 C&lt;has_skip&gt;

  if ( $result-&gt;has_skip ) { ... }

Returns a boolean value indicating whether or not this test has a SKIP
directive.

=head3 C&lt;has_todo&gt;

  if ( $result-&gt;has_todo ) { ... }

Returns a boolean value indicating whether or not this test has a TODO
directive.

=head3 C&lt;as_string&gt;

  print $result-&gt;as_string;

This method prints the test as a string.  It will probably be similar, but
not necessarily identical, to the original test line.  Directives are
capitalized, some whitespace may be trimmed and a test number will be added if
it was not present in the original line.  If you need the original text of the
test line, use the C&lt;raw&gt; method.

=cut

sub as_string {
    my $self   = shift;
    my $string = $self-&gt;ok . " " . $self-&gt;number;
    if ( my $description = $self-&gt;description ) {
        $string .= " $description";
    }
    if ( my $directive = $self-&gt;directive ) {
        my $explanation = $self-&gt;explanation;
        $string .= " # $directive $explanation";
    }
    return $string;
}

##############################################################################

=head3 C&lt;is_unplanned&gt;

  if ( $test-&gt;is_unplanned ) { ... }
  $test-&gt;is_unplanned(1);

If a test number is greater than the number of planned tests, this method will
return true.  Unplanned tests will I&lt;always&gt; return false for C&lt;is_ok&gt;,
regardless of whether or not the test C&lt;has_todo&gt;.

Note that if tests have a trailing plan, it is not possible to set this
property for unplanned tests as we do not know it's unplanned until the plan
is reached:

  print &lt;&lt;'END';
  ok 1
  ok 2
  1..1
  END

=cut

sub is_unplanned {
    my $self = shift;
    return ( $self-&gt;{unplanned} || '' ) unless @_;
    $self-&gt;{unplanned} = !!shift;
    return $self;
}

1;
</pre></body></html>