NAME
TB2::History - Manage the history of test results
SYNOPSIS
use TB2::History;
my $history = TB2::History->new;
my $ec = TB2::EventCoordinator->create(
history => $history
);
my $pass = TB2::Result->new_result( pass => 1 );
$ec->post_event( $pass );
$ec->history->can_succeed; # true
my $result = TB2::Result->new_result( pass => 0 );
$ec->post_event( $pass );
$ec->history->can_succeed; # false
DESCRIPTION
This object stores and manages the history of test results.
It is a TB2::EventHandler.
METHODS
Constructors
new
my $history = TB2::History->new;
Creates a new, unique History object.
Misc
object_id
my $id = $thing->object_id;
Returns an identifier for this object unique to the running process. The identifier is fairly simple and easily predictable.
See TB2::HasObjectID
Accessors
Unless otherwise stated, these are all accessor methods of the form:
my $value = $history->method; # get
$history->method($value); # set
Events
events
A TB2::Stack of events, that include Result objects.
event_count
Get the count of events that are on the stack.
Results
results
A TB2::Stack of Result objects.
# The result of test #4.
my $result = $history->results->[3];
result_count
Get the count of results stored in the stack.
NOTE: This could be diffrent from the number of tests that have been seen, to get that count use test_count.
has_results
Returns true if we have stored results, false otherwise.
Statistics
test_count
A count of the number of tests that have been added to results. This value is not guaranteed to be the same as results_count if you have altered the results_stack. This is a static counter of the number of tests that have been seen, not the number of results stored.
pass_count
A count of the number of passed tests have been added to results.
fail_count
A count of the number of failed tests have been added to results.
todo_count
A count of the number of TODO tests have been added to results.
skip_count
A count of the number of SKIP tests have been added to results.
can_succeed
Returns true if the test can still succeed. That is, if nothing yet has happened to cause it to fail and the plan can be fulfilled.
For example, running too few tests is ok, but if too many have been run the test can never succeed.
In another example, if there is no plan yet issued, there is no plan to violate.
test_was_successful
my $test_passed = $history->test_was_successful;
This returns true if the test is considered successful, false otherwise.
The conditions for a test passing are...
* test_start, set_plan and test_end events were seen * the plan is satisfied (the right number of Results were seen) * no Results were seen out of order according to their test_number * For every Result, is_fail() is false * If asked at END time, the test process is exiting with 0
Note that this will not be true until test_end
has been seen. Until then, use can_succeed
.
in_test
my $am_in_test = $history->in_test;
Returns true if we're in the middle of a test, that is a test_start
event was seen but a test_end
event has not.
done_testing
my $testing_is_done = $history->done_testing;
Returns true if testing was started and it is done. That is, both a test_start
and a test_end
event has been seen.
plan
my $plan = $history->plan;
Returns the plan event for the current test, if any.
test_start
my $test_start = $history->test_start;
Returns the test_start
event, if it has been seen.
test_end
my $test_end = $history->test_end;
Returns the test_end
event, if it has been seen.
is_subtest
my $is_subtest = $history->is_subtest;
Returns whether this $history represents a subtest.
subtest_depth
my $depth = $history->subtest_depth;
Returns how deep in subtests the current test is.
The top level test has a depth of 0. The first subtest is 1, the next nested is 2 and so on.
subtest_start
my $subtest_start = $history->subtest_start;
Returns the subtest_start
event, if it has been seen.
This is the event for the subtest about to start or which has just ended. It is not the event for the current subtest.
abort
my $abort = $history->abort;
Returns the last abort
event seen, if any.
pid_at_test_start
my $process_id = $history->pid_at_test_start;
History records the $process_id at the time the test has started.
is_child_process
my $is_child = $history->is_child_process;
Returns true if the current process is a child of the process which started the test.
HISTORY INTERACTION
consume
$history->consume($old_history);
Appends $old_history results in to $history's results stack.