NAME

Test::Builder2::History - Manage the history of test results

SYNOPSIS

use Test::Builder2::History;

# This is a shared singleton object
my $history = Test::Builder2::History->singleton;
my $result  = Test::Builder2::Result->new_result( pass => 1 );

$history->add_test_history( $result );
$history->is_passing;

DESCRIPTION

This object stores and manages the history of test results.

METHODS

Constructors

singleton

my $history = Test::Builder2::History->singleton;
Test::Builder2::History->singleton($history);

Gets/sets the shared instance of the history object.

Test::Builder2::History is a singleton. singleton() will return the same object every time so all users can have a shared history. If you want your own history, call create() instead.

create

my $history = Test::Builder2::History->create;

Creates a new, unique History object with its own Counter.

Accessors

Unless otherwise stated, these are all accessor methods of the form:

my $value = $history->method;       # get
$history->method($value);           # set

counter

A Test::Builder2::Counter object being used to store the count.

Defaults to the singleton.

current_count

Returns the current number in the counter.

next_count

Returns the next number in the counter.

results

An array ref of the test history expressed as Result objects. Remember that test 1 is index 0.

# The result of test #4.
my $result = $history->results->[3];

should_keep_history

If set to false, no history will be recorded. This is handy for very long running tests that might consume a lot of memeory.

Defaults to true.

Other Methods

add_test_history

$history->add_test_history(@results);

Adds the @results to the existing test history at the point indicated by counter. That's usually the end of the history, but if counter is moved backwards it will overlay existing history.

@results is a list of Result objects.

counter will be incremented by the number of @results.

summary

my @summary = $history->results;

Returns a list of true/false values for each test result indicating if it passed or failed.

is_passing

my $is_passing = $history->is_passing;

Returns true if all the tests passed, false otherwise.