The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test::Run::Core - Run Perl standard test scripts with statistics

VERSION

Version 0.0108

SYNOPSIS

  use Test::Run::Obj;

  my $tester = Test::Run::Obj->new({'test_files' => \@test_files});
  $tester->runtests();

DESCRIPTION

STOP! If all you want to do is write a test script, consider using Test::Simple. Test::Run::Core is the module that reads the output from Test::Simple, Test::More and other modules based on Test::Builder. You don't need to know about Test::Run::Core to use those modules.

Test::Run::Core runs tests and expects output from the test in a certain format. That format is called TAP, the Test Anything Protocol. It is defined in Test::Harness::TAP.

$tester-runtests()> runs all the testscripts named as arguments and checks standard output for the expected strings in TAP format.

Test::Run::Obj is an applicative derived class of Test::Run::Core that provides a programmer API for running and analyzing the output of TAP files. For calling from the command line, look at Test::Run::CmdLine.

Taint mode

Test::Run will honor the -T or -t in the #! line on your test files. So if you begin a test with:

    #!perl -T

the test will be run with taint mode on.

Object Parameters

These parameters are accessors. They can be set at object creation by passing their name along with a value on the constructor (along with the compulsory 'test_files' argument):

    my $tester = Test::Run::Obj->new(
        {
            'test_files' => \@mytests,
            'Verbose' => 1,
        }
    );

Alternatively, before runtests() is called, they can be set by passing a value to their accessor:

    $tester->Verbose(1);
$self->Verbose()

The object variable $self->Verbose() can be used to let runtests() display the standard output of the script without altering the behavior otherwise. The runprove utility's -v flag will set this.

$self->Leaked_Dir()

When set to the name of a directory, $tester will check after each test whether new files appeared in that directory, and report them as

  LEAKED FILES: scr.tmp 0 my.db

If relative, directory name is with respect to the current directory at the moment $tester->runtests() was called. Putting the absolute path into Leaked_Dir will give more predictable results.

$self->Debug()

If $self->Debug() is true, Test::Run will print debugging information about itself as it runs the tests. This is different from $self->Verbose(), which prints the output from the test being run.

$self->Columns()

This value will be used for the width of the terminal. If it is not set then it will default to 80.

$self->Timer()

If set to true, and Time::HiRes is available, print elapsed seconds after each test file.

$self->NoTty()

When set to a true value, forces it to behave as though STDOUT were not a console. You may need to set this if you don't want harness to output more frequent progress messages using carriage returns. Some consoles may not handle carriage returns properly (which results in a somewhat messy output).

$self->Test_Interprter()

Usually your tests will be run by $^X, the currently-executing Perl. However, you may want to have it run by a different executable, such as a threading perl, or a different version.

$self->Switches() and $self->Switches_Env()

These two values will be prepended to the switches used to invoke perl on each test. For example, setting one of them to -W will run all tests with all warnings enabled.

The difference between them is that Switches_Env() is expected to be filled in by the environment and Switches() from other sources (like the programmer).

Failure

When tests fail, analyze the summary report:

  t/base..............ok
  t/nonumbers.........ok
  t/ok................ok
  t/test-harness......ok
  t/waterloo..........dubious
          Test returned status 3 (wstat 768, 0x300)
  DIED. FAILED tests 1, 3, 5, 7, 9, 11, 13, 15, 17, 19
          Failed 10/20 tests, 50.00% okay
  Failed Test  Stat Wstat Total Fail  Failed  List of Failed
  -----------------------------------------------------------------------
  t/waterloo.t    3   768    20   10  50.00%  1 3 5 7 9 11 13 15 17 19
  Failed 1/5 test scripts, 80.00% okay. 10/44 subtests failed, 77.27% okay.

Everything passed but t/waterloo.t. It failed 10 of 20 tests and exited with non-zero status indicating something dubious happened.

The columns in the summary report mean:

Failed Test

The test file which failed.

Stat

If the test exited with non-zero, this is its exit status.

Wstat

The wait status of the test.

Total

Total number of tests expected to run.

Fail

Number which failed, either from "not ok" or because they never ran.

Failed

Percentage of the total tests which failed.

List of Failed

A list of the tests which failed. Successive failures may be abbreviated (ie. 15-20 to indicate that tests 15, 16, 17, 18, 19 and 20 failed).

Functions

Test::Run currently only has one interface function, here it is.

runtests
  my $allok = $self->runtests();

This runs all the given @test_files and divines whether they passed or failed based on their output to STDOUT (details above). It prints out each individual test which failed along with a summary report and a how long it all took.

It returns true if everything was ok. Otherwise it will die() with one of the messages in the DIAGNOSTICS section.

EXPORT

None.

DIAGNOSTICS

All tests successful.\nFiles=%d, Tests=%d, %s

If all tests are successful some statistics about the performance are printed.

FAILED tests %s\n\tFailed %d/%d tests, %.2f%% okay.

For any single script that has failing subtests statistics like the above are printed.

Test returned status %d (wstat %d)

Scripts that return a non-zero exit status, both $? >> 8 and $? are printed in a message similar to the above.

Failed 1 test, %.2f%% okay. %s
Failed %d/%d tests, %.2f%% okay. %s

If not all tests were successful, the script dies with one of the above messages.

FAILED--Further testing stopped: %s

If a single subtest decides that further testing will not make sense, the script dies with this message.

ENVIRONMENT VARIABLES THAT TEST::HARNESS SETS

Test::Run sets these before executing the individual tests.

HARNESS_ACTIVE

This is set to a true value. It allows the tests to determine if they are being executed through the harness or by any other means.

HARNESS_VERSION

This is the version of Test::Run.

EXAMPLE

TODO: FIXME

Here's how Test::Run tests itself

  $ cd ~/src/devel/Test-Harness
  $ perl -Mblib -e 'use Test::Run qw(&runtests $verbose);
    $verbose=0; runtests @ARGV;' t/*.t
  Using /home/schwern/src/devel/Test-Harness/blib
  t/base..............ok
  t/nonumbers.........ok
  t/ok................ok
  t/test-harness......ok
  All tests successful.
  Files=4, Tests=24, 2 wallclock secs ( 0.61 cusr + 0.41 csys = 1.02 CPU)

SEE ALSO

The included prove utility for running test scripts from the command line, Test and Test::Simple for writing test scripts, Benchmark for the underlying timing routines, and Devel::Cover for test coverage analysis.

TODO

Provide a way of running tests quietly (ie. no printing) for automated validation of tests. This will probably take the form of a version of runtests() which rather than printing its output returns raw data on the state of the tests. (Partially done in Test::Run::Straps)

Document the format.

Fix HARNESS_COMPILE_TEST without breaking its core usage.

Figure a way to report test names in the failure summary.

Rework the test summary so long test names are not truncated as badly. (Partially done with new skip test styles)

Add option for coverage analysis.

Trap STDERR.

Implement Straps total_results()

Remember exit code

Completely redo the print summary code.

Implement Straps callbacks. (experimentally implemented)

Straps->analyze_file() not taint clean, don't know if it can be

Fix that damned VMS nit.

HARNESS_TODOFAIL to display TODO failures

Add a test for verbose.

Change internal list of test results to a hash.

Fix stats display when there's an overrun.

Fix so perls with spaces in the filename work.

Keeping whittling away at _run_all_tests()

Clean up how the summary is printed. Get rid of those damned formats.

BUGS

HARNESS_COMPILE_TEST currently assumes it's run from the Perl source directory.

Please use the CPAN bug ticketing system at http://rt.cpan.org/. You can also mail bugs, fixes and enhancements to <bug-test-harness at rt.cpan.org>.

AUTHORS

Test::Run::Obj is based on Test::Harness, and has later been spinned off as a separate module.

Test:Harness Authors

Either Tim Bunce or Andreas Koenig, we don't know. What we know for sure is, that it was inspired by Larry Wall's TEST script that came with perl distributions for ages. Numerous anonymous contributors exist. Andreas Koenig held the torch for many years, and then Michael G Schwern.

Test::Harness was then maintained by Andy Lester <andy at petdance.com>.

Test::Run::Obj Authors

Shlomi Fish <shlomif@iglu.org.il>

BUGS

Please report any bugs or feature requests to bug-test-run at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test::Run. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Test::Run::Core

You can also look for information at:

SOURCE AVAILABILITY

The latest source of Test::Run is available from its BerliOS Subversion repository:

https://svn.berlios.de/svnroot/repos/web-cpan/Test-Harness-NG/

COPYRIGHT

Copyright 2002-2005 by Michael G Schwern <schwern at pobox.com>, Andy Lester <andy at petdance.com>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://www.perl.com/perl/misc/Artistic.html.