TB2::History - Manage the history of test results
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
This object stores and manages the history of test results.
It is a TB2::EventHandler.
my $history = TB2::History->new;
Creates a new, unique History object.
my $id = $thing->object_id;
Returns an identifier for this object unique to the running process. The identifier is fairly simple and easily predictable.
Unless otherwise stated, these are all accessor methods of the form:
my $value = $history->method; # get $history->method($value); # set
A TB2::Stack of events, that include Result objects.
Get the count of events that are on the stack.
A TB2::Stack of Result objects.
# The result of test #4. my $result = $history->results->;
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.
Returns true if we have stored results, false otherwise.
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.
A count of the number of passed tests have been added to results.
A count of the number of failed tests have been added to results.
A count of the number of TODO tests have been added to results.
A count of the number of SKIP tests have been added to results.
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.
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
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.
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.
my $counter = $formatter->counter; $formatter->counter($counter);
Gets/sets the result counter. This is usually the number of results seen, but it is not guaranteed to be so. It can be reset.
my $plan = $history->plan;
Returns the plan event for the current test, if any.
my $test_start = $history->test_start;
test_start event, if it has been seen.
my $test_end = $history->test_end;
test_end event, if it has been seen.
my $subtest = $history->subtest;
Returns the current
subtest event for this object, if there is one.
my $is_subtest = $history->is_subtest;
Returns whether this $history represents a subtest.
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.
my $subtest_start = $history->subtest_start;
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.
my $abort = $history->abort;
Returns the last
abort event seen, if any.
my $process_id = $history->pid_at_test_start;
History records the $process_id at the time the test has started.
my $is_child = $history->is_child_process;
Returns true if the current process is a child of the process which started the test.
Appends $old_history results in to $history's results stack.