View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Curtis "Ovid" Poe > TAPx-Parser > TAPx::Harness



Annotate this POD

Module Version: 0.50_07   Source  


TAPx::Harness - Run Perl test scripts with statistics


Version 0.50_07


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


 use TAPx::Harness;
 my $harness = TAPx::Harness->new( \%args );


Class methods


 my %args = (
    verbose => 1,
    lib     => [ 'lib', 'blib/lib' ],
 my $harness = TAPx::Harness->new( \%args );

The constructor returns a new TAPx::Harness object. It accepts an optional hashref whose allowed keys are:

Instance Methods



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 TAPx::Parser::new() as a source. See TAPx::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.


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

Tests will be run in the order found.


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


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


  $harness->summary( \%args );

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



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



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


 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.


 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



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


WARNING: this functionality is still experimental. While we intend to support it, the file format may change.

Sometimes you want to use different executables to run different tests. If that's the case, you'll need to create an execrc file. This file should be a YAML file. This should be representative a hash with one key, tests, whose value is an array of array references. Each terminating array reference should be a list of the exact arguments which eventually get executed.

 # this is the default for all files
     - /usr/bin/perl
     - -wT
     - *
 # whoops!  We have a ruby test here!
     - /usr/bin/ruby
     - t/ruby.t
 # let's test some web pages
     - /usr/bin/perl
     - -w
     - bin/
     - /usr/bin/perl
     - -w
     - bin/

If the terminating element in an array is '*', then the rest of the array are the default arguments used to run any test.

Blank lines are allowed. Lines beginning with a '#' are comments (the '#' may have spaces in front of it).

So for the above execrc file, if it's named 'my_execrc' (as it is in the examples/ directory which comes with this distribution), then you could potentially run it like this, if you're using the runtests utility:

 runtests --execrc my_execrc t/ - < list_of_urls.txt

Then for a test named t/test_is_written_in_ruby.t, it will be executed with:

 /usr/bin/ruby -w t/test_is_written_in_ruby.t

If the list of urls contains "", it will be executed as follows:


Of course, if outputs anything other than TAP, this will fail.

See the README in the examples directory for a ready-to-run example.


If you like the runtests utility and TAPx::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 runtests utility like so:

 runtests --harness My::Test::Harness

Note that while runtests 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.



syntax highlighting: