TAP::Harness - Run test scripts with statistics
use TAP::Harness; my $harness = TAP::Harness->new( \%args ); $harness->runtests(@tests);
my %args = ( verbosity => 1, lib => [ 'lib', 'blib/lib' ], ) my $harness = TAP::Harness->new( \%args );
The constructor returns a new "TAP::Harness" object. It accepts an optional hashref whose allowed keys are:
1 verbose Print individual test results to STDOUT. 0 normal -1 quiet Suppress some test output (mostly failures while tests are running). -2 really quiet Suppress everything but the tests summary.
exec => ['/usr/bin/ruby', '-w']
errors => 1
Any keys for which the value is "undef" will be ignored.
$harness->runtests(@tests);
Accepts and array of @tests to be run. This should generally be the names of test files, but this is not required. Each element in @tests will be passed to "TAP::Parser::new()" as a "source". See TAP::Parser for more information.
It is possible to provide aliases that will be displayed in place of the test name by supplying the test as a reference to an array containing "[ $test, $alias ]":
$harness->runtests( [ 't/foo.t', 'Foo Once' ], [ 't/foo.t', 'Foo Twice' ] );
Normally it is an error to attempt to run the same test twice. Aliases allow you to overcome this limitation by giving each run of the test a unique name.
Tests will be run in the order found.
If the environment variable "PERL_TEST_HARNESS_DUMP_TAP" is defined it should name a directory into which a copy of the raw TAP for each test will be written. TAP is written to files named for each test. Subdirectories will be created as needed.
Returns a TAP::Parser::Aggregator containing the test results.
$harness->aggregate_tests( $aggregate, @tests );
Run the named tests and display a summary of result. Tests will be run in the order found.
Test results will be added to the supplied TAP::Parser::Aggregator. "aggregate_tests" may be called multiple times to run several sets of tests. Multiple "Test::Harness" instances may be used to pass results to a single aggregator so that different parts of a complex test suite may be run using different "TAP::Harness" settings. This is useful, for example, in the case where some tests should run in parallel but others are unsuitable for parallel execution.
my $formatter = TAP::Formatter::Console->new; my $ser_harness = TAP::Harness->new( { formatter => $formatter } ); my $par_harness = TAP::Harness->new( { formatter => $formatter, jobs => 9 } ); my $aggregator = TAP::Parser::Aggregator->new;
$aggregator->start(); $ser_harness->aggregate_tests( $aggregator, @ser_tests ); $par_harness->aggregate_tests( $aggregator, @par_tests ); $aggregator->stop(); $formatter->summary( $aggregator );
Note that for simpler testing requirements it will often be possible to replace the above code with a single call to "runtests".
Each elements of the @tests array is either
When you supply a separate display name it becomes possible to run a test more than once; the display name is effectively the alias by which the test is known inside the harness. The harness doesn't care if it runs the same script more than once when each invocation uses a different name.
Returns the number of concurrent test runs the harness is handling. For the default harness this value is always 1. A parallel harness such as TAP::Harness::Parallel will override this to return the number of jobs it is handling.
If true the harness will attempt to fork and run the parser for each test in a separate process. Currently this option requires Parallel::Iterator to be installed.
The following methods are ones you may wish to override if you want to subclass "TAP::Harness".
$harness->summary( \%args );
"summary" prints the summary report after all tests are run. The argument is a hashref with the following keys:
$self->output(timestr( timediff( Benchmark->new, $start_time ), 'nop' ));
my $aggregate = $args->{aggregate}; my $tests = $args->{tests};
for my $name ( @$tests ) { my ($parser) = $aggregate->parsers($test); ... do something with $parser }
This is a bit clunky and will be cleaned up in a later release.
Make a new parser and display formatter session. Typically used and/or overridden in subclasses.
my ( $parser, $session ) = $harness->make_parser;
Terminate use of a parser. Typically used and/or overridden in subclasses. The parser isn't destroyed as a result of this.
prove --harness My::Test::Harness
Note that while "prove" accepts a list of tests (or things to be tested), "new" has a fairly rich set of arguments. You'll probably want to read over this code carefully to see how all of them are being used.
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |