The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test::Builder2::Result::Base - Store the result of an assert

SYNOPSIS

    # Use TB2::Result as a factory, not TB2::Result::Base directly
    my $result = Test::Builder2::Result->new_result(%options);

DESCRIPTION

This represents the result of an assert, whether it passed or failed, if it had any modifiers (directives), additional diagnostic information, etc...

NOTE: This object is in a very high state of flux.

Overloading

A Result object used as a boolean will be true if the assert passed, false otherwise.

METHODS

Attributes

description

name

    my $name = $result->name;

The name of the assert. For example...

    # The name is "addition"
    ok( 1 + 1, "addition" );

description is the more generic alias to this method.

diagnostic

diag

    my $diag = $result->diag;

The structured diagnostics associated with this result.

Diagnostics are currently an array ref of key/value pairs. Its an array ref to keep the order. This will probably change.

id

line

    my $line = $result->line;

The line number upon which this assert was run.

Because a single result can represent a stack of actual asserts, this is generally the location of the first assert in the stack.

id is a more generic alias.

location

file

    my $file = $result->file;

The file whre this assert was run.

Like line, this represents the top of the assert stack.

reason

    my $reason = $result->reason;

The reason for any modifiers.

test_number

    my $number = $result->test_number;

The number associated with this test, if any.

NOTE that most testing systems don't number their results. And even TAP tests are not required to do so.

Methods

event_type

    my $type = $result->event_type;

Returns the type of this Event, for differenciation between other Event objects.

The type is "result".

as_hash

    my $hash = $self->as_hash;

Returns the attributes of a result as a hash reference.

Useful for quickly dumping the contents of a result.

literal_pass

Returns true if the assert passed without regard to any modifiers.

is_unknown

Returns true if the result is unknown. This usually indicates that there should be a test here but none was written or it was skipped.

An example is a test skipped because it is not relevant to the current environment (like a Windows specific test on a Unix machine).

is_pass

Returns true if this test is considered a pass after consideration of any modifiers.

For example, the result of a TODO test is always considered a pass no matter what the actual result of the assert is.

is_fail

The opposite of is_pass.

is_todo

Returns true if this result is TODO.

is_skip

Returns true if the assert was recording as existing but never run.

SEE ALSO

Test::Builder2::Result Factory for creating results

Test::Builder2::History Store the results

Test::Builder2::Formatter Format results for display