Andy Armstrong > Test-Harness-2.99_01 > TAP::Harness

Download:
Test-Harness-2.99_01.tar.gz

Dependencies

Annotate this POD (1)

Website

CPAN RT

New  20
Open  19
View/Report Bugs
Module Version: 2.99_01   Source   Latest Release: Test-Harness-3.34

NAME ^

TAP::Harness - Run Perl test scripts with statistics

VERSION ^

Version 2.99_01

DESCRIPTION ^

This is a simple test harness which allows tests to be run and results automatically aggregated and output to STDOUT.

SYNOPSIS ^

 use TAP::Harness;
 my $harness = TAP::Harness->new( \%args );
 $harness->runtests(@tests);

METHODS ^

Class Methods

new

 my %args = (
    verbose => 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:

Instance Methods

runtests

  $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.

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.

aggregate_tests

  $harness->aggregate_tests( $aggregate, @tests );

Tests will be run in the order found.

SUBCLASSING ^

TAP::Harness is designed to be (mostly) easy to subclass. If you don't like how a particular feature functions, just override the desired methods.

Methods

The following methods are one's you may wish to override if you want to subclass TAP::Harness.

summary

  $harness->summary( \%args );

summary prints the summary report after all tests are run. The argument is a hashref with the following keys:

output

  $harness->output(@list_of_strings_to_output);

All output from TAP::Harness is driven through this method. If you would like to redirect output somewhere else, just override this method.

failure_output

  $harness->failure_output(@list_of_strings_to_output);

Identical to output, this method is called for any output which represents a failure.

balanced_range

 my @ranges = $harness->balanced_range( $limit, @numbers );

Given a limit in the number of characters and a list of numbers, this method first creates a range of numbers with range and then groups them into individual strings which are roughly the length of $limit. Returns an array of strings.

range

 my @range = $harness->range(@list_of_numbers);

Taks a list of numbers, sorts them, and returns a list of ranged strings:

 print join ', ' $harness->range( 2, 7, 1, 3, 10, 9  );
 # 1-3, 7, 9-10

output_test_failure

  $harness->output_test_failure($parser);

As individual test programs are run, if a test program fails, this method is called to spit out the list of failed tests.

REPLACING ^

If you like the prove utility and TAP::Parser but you want your own harness, all you need to do is write one and provide new and runtests methods. Then you can use the prove utility like so:

 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.

SEE ALSO ^

Test::Harness

syntax highlighting: