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.
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->[3];
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 can_succeed.
test_end
can_succeed
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.
test_start
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 $plan = $history->plan;
Returns the plan event for the current test, if any.
my $test_start = $history->test_start;
Returns the test_start event, if it has been seen.
my $test_end = $history->test_end;
Returns the test_end event, if it has been seen.
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;
Returns the subtest_start event, if it has been seen.
subtest_start
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.
abort
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.
$history->consume($old_history);
Appends $old_history results in to $history's results stack.
To install Test::Simple, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Simple
CPAN shell
perl -MCPAN -e shell install Test::Simple
For more information on module installation, please visit the detailed CPAN module installation guide.