.\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sh \" Subsection heading
.br
.if t .Sp
.ne 5
.PP
\fB\\$1\fR
.PP
..
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. | will give a
.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
.\" expand to `' in nroff, nothing in troff, for use with C<>.
.tr \(*W-|\(bv\*(Tr
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
'br\}
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. nr % 0
. rr F
.\}
.\"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.hy 0
.if n .na
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
. \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "Test::Harness 3"
.TH Test::Harness 3 "2002-11-24" "perl v5.8.0" "Perl Programmers Reference Guide"
.SH "NAME"
Test::Harness \- run perl standard test scripts with statistics
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\& use Test::Harness;
.Ve
.PP
.Vb 1
\& runtests(@test_files);
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
\&\fB\s-1STOP\s0!\fR If all you want to do is write a test script, consider using
Test::Simple. Otherwise, read on.
.PP
(By using the Test module, you can write test scripts without
knowing the exact output this module expects. However, if you need to
know the specifics, read on!)
.PP
Perl test scripts print to standard output \f(CW"ok N"\fR for each single
test, where \f(CW\*(C`N\*(C'\fR is an increasing sequence of integers. The first line
output by a standard test script is \f(CW"1..M"\fR with \f(CW\*(C`M\*(C'\fR being the
number of tests that should be run within the test
script. Test::Harness::runtests(@tests) runs all the testscripts
named as arguments and checks standard output for the expected
\&\f(CW"ok N"\fR strings.
.PP
After all tests have been performed, \fIruntests()\fR prints some
performance statistics that are computed by the Benchmark module.
.Sh "The test script output"
.IX Subsection "The test script output"
The following explains how Test::Harness interprets the output of your
test program.
.IP "\fB'1..M'\fR" 4
.IX Item "'1..M'"
This header tells how many tests there will be. For example, \f(CW1..10\fR
means you plan on running 10 tests. This is a safeguard in case your
test dies quietly in the middle of its run.
.Sp
It should be the first non-comment line output by your test program.
.Sp
In certain instances, you may not know how many tests you will
ultimately be running. In this case, it is permitted for the 1..M
header to appear as the \fBlast\fR line output by your test (again, it
can be followed by further comments).
.Sp
Under \fBno\fR circumstances should 1..M appear in the middle of your
output or more than once.
.IP "\fB'ok', 'not ok'. Ok?\fR" 4
.IX Item "'ok', 'not ok'. Ok?"
Any output from the testscript to standard error is ignored and
bypassed, thus will be seen by the user. Lines written to standard
output containing \f(CW\*(C`/^(not\es+)?ok\eb/\*(C'\fR are interpreted as feedback for
\&\fIruntests()\fR. All other lines are discarded.
.Sp
\&\f(CW\*(C`/^not ok/\*(C'\fR indicates a failed test. \f(CW\*(C`/^ok/\*(C'\fR is a successful test.
.IP "\fBtest numbers\fR" 4
.IX Item "test numbers"
Perl normally expects the 'ok' or 'not ok' to be followed by a test
number. It is tolerated if the test numbers after 'ok' are
omitted. In this case Test::Harness maintains temporarily its own
counter until the script supplies test numbers again. So the following
test script
.Sp
.Vb 8
\& print <<END;
\& 1..6
\& not ok
\& ok
\& not ok
\& ok
\& ok
\& END
.Ve
.Sp
will generate
.Sp
.Vb 2
\& FAILED tests 1, 3, 6
\& Failed 3/6 tests, 50.00% okay
.Ve
.IP "\fBtest names\fR" 4
.IX Item "test names"
Anything after the test number but before the # is considered to be
the name of the test.
.Sp
.Vb 1
\& ok 42 this is the name of the test
.Ve
.Sp
Currently, Test::Harness does nothing with this information.
.IP "\fBSkipping tests\fR" 4
.IX Item "Skipping tests"
If the standard output line contains the substring \f(CW\*(C` # Skip\*(C'\fR (with
variations in spacing and case) after \f(CW\*(C`ok\*(C'\fR or \f(CW\*(C`ok NUMBER\*(C'\fR, it is
counted as a skipped test. If the whole testscript succeeds, the
count of skipped tests is included in the generated output.
\&\f(CW\*(C`Test::Harness\*(C'\fR reports the text after \f(CW\*(C` # Skip\eS*\es+\*(C'\fR as a reason
for skipping.
.Sp
.Vb 1
\& ok 23 # skip Insufficient flogiston pressure.
.Ve
.Sp
Similarly, one can include a similar explanation in a \f(CW1..0\fR line
emitted if the test script is skipped completely:
.Sp
.Vb 1
\& 1..0 # Skipped: no leverage found
.Ve
.IP "\fBTodo tests\fR" 4
.IX Item "Todo tests"
If the standard output line contains the substring \f(CW\*(C` # TODO\*(C'\fR after
\&\f(CW\*(C`not ok\*(C'\fR or \f(CW\*(C`not ok NUMBER\*(C'\fR, it is counted as a todo test. The text
afterwards is the thing that has to be done before this test will
succeed.
.Sp
.Vb 1
\& not ok 13 # TODO harness the power of the atom
.Ve
.Sp
These tests represent a feature to be implemented or a bug to be fixed
and act as something of an executable \*(L"thing to do\*(R" list. They are
\&\fBnot\fR expected to succeed. Should a todo test begin succeeding,
Test::Harness will report it as a bonus. This indicates that whatever
you were supposed to do has been done and you should promote this to a
normal test.
.IP "\fBBail out!\fR" 4
.IX Item "Bail out!"
As an emergency measure, a test script can decide that further tests
are useless (e.g. missing dependencies) and testing should stop
immediately. In that case the test script prints the magic words
.Sp
.Vb 1
\& Bail out!
.Ve
.Sp
to standard output. Any message after these words will be displayed by
\&\f(CW\*(C`Test::Harness\*(C'\fR as the reason why testing is stopped.
.IP "\fBComments\fR" 4
.IX Item "Comments"
Additional comments may be put into the testing output on their own
lines. Comment lines should begin with a '#', Test::Harness will
ignore them.
.Sp
.Vb 4
\& ok 1
\& # Life is good, the sun is shining, RAM is cheap.
\& not ok 2
\& # got 'Bush' expected 'Gore'
.Ve
.IP "\fBAnything else\fR" 4
.IX Item "Anything else"
Any other output Test::Harness sees it will silently ignore \fB\s-1BUT\s0 \s-1WE\s0
\&\s-1PLAN\s0 \s-1TO\s0 \s-1CHANGE\s0 \s-1THIS\s0!\fR If you wish to place additional output in your
test script, please use a comment.
.Sh "Taint mode"
.IX Subsection "Taint mode"
Test::Harness will honor the \f(CW\*(C`\-T\*(C'\fR in the #! line on your test files. So
if you begin a test with:
.PP
.Vb 1
\& #!perl -T
.Ve
.PP
the test will be run with taint mode on.
.Sh "Configuration variables."
.IX Subsection "Configuration variables."
These variables can be used to configure the behavior of
Test::Harness. They are exported on request.
.IP "\fB$Test::Harness::verbose\fR" 4
.IX Item "$Test::Harness::verbose"
The global variable \f(CW$Test::Harness::verbose\fR is exportable and can be
used to let \fIruntests()\fR display the standard output of the script
without altering the behavior otherwise.
.IP "\fB$Test::Harness::switches\fR" 4
.IX Item "$Test::Harness::switches"
The global variable \f(CW$Test::Harness::switches\fR is exportable and can be
used to set perl command line options used for running the test
script(s). The default value is \f(CW\*(C`\-w\*(C'\fR.
.Sh "Failure"
.IX Subsection "Failure"
It will happen, your tests will fail. After you mop up your ego, you
can begin examining the summary report:
.PP
.Vb 12
\& 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.
.Ve
.PP
Everything passed but t/waterloo.t. It failed 10 of 20 tests and
exited with non-zero status indicating something dubious happened.
.PP
The columns in the summary report mean:
.IP "\fBFailed Test\fR" 4
.IX Item "Failed Test"
The test file which failed.
.IP "\fBStat\fR" 4
.IX Item "Stat"
If the test exited with non\-zero, this is its exit status.
.IP "\fBWstat\fR" 4
.IX Item "Wstat"
The wait status of the test \fIumm, I need a better explanation here\fR.
.IP "\fBTotal\fR" 4
.IX Item "Total"
Total number of tests expected to run.
.IP "\fBFail\fR" 4
.IX Item "Fail"
Number which failed, either from \*(L"not ok\*(R" or because they never ran.
.IP "\fBFailed\fR" 4
.IX Item "Failed"
Percentage of the total tests which failed.
.IP "\fBList of Failed\fR" 4
.IX Item "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).
.Sh "Functions"
.IX Subsection "Functions"
Test::Harness currently only has one function, here it is.
.IP "\fBruntests\fR" 4
.IX Item "runtests"
.Vb 1
\& my $allok = runtests(@test_files);
.Ve
.Sp
This runs all the given \f(CW@test_files\fR and divines whether they passed
or failed based on their output to \s-1STDOUT\s0 (details above). It prints
out each individual test which failed along with a summary report and
a how long it all took.
.Sp
It returns true if everything was ok. Otherwise it will \fIdie()\fR with
one of the messages in the \s-1DIAGNOSTICS\s0 section.
.SH "EXPORT"
.IX Header "EXPORT"
\&\f(CW&runtests\fR is exported by Test::Harness per default.
.PP
\&\f(CW$verbose\fR and \f(CW$switches\fR are exported upon request.
.SH "DIAGNOSTICS"
.IX Header "DIAGNOSTICS"
.ie n .IP """All tests successful.\enFiles=%d, Tests=%d, %s""" 4
.el .IP "\f(CWAll tests successful.\enFiles=%d, Tests=%d, %s\fR" 4
.IX Item "All tests successful.nFiles=%d, Tests=%d, %s"
If all tests are successful some statistics about the performance are
printed.
.ie n .IP """FAILED tests %s\en\etFailed %d/%d tests, %.2f%% okay.""" 4
.el .IP "\f(CWFAILED tests %s\en\etFailed %d/%d tests, %.2f%% okay.\fR" 4
.IX Item "FAILED tests %sntFailed %d/%d tests, %.2f%% okay."
For any single script that has failing subtests statistics like the
above are printed.
.ie n .IP """Test returned status %d (wstat %d)""" 4
.el .IP "\f(CWTest returned status %d (wstat %d)\fR" 4
.IX Item "Test returned status %d (wstat %d)"
Scripts that return a non-zero exit status, both \f(CW\*(C`$? >> 8\*(C'\fR
and \f(CW$?\fR are printed in a message similar to the above.
.ie n .IP """Failed 1 test, %.2f%% okay. %s""" 4
.el .IP "\f(CWFailed 1 test, %.2f%% okay. %s\fR" 4
.IX Item "Failed 1 test, %.2f%% okay. %s"
.PD 0
.ie n .IP """Failed %d/%d tests, %.2f%% okay. %s""" 4
.el .IP "\f(CWFailed %d/%d tests, %.2f%% okay. %s\fR" 4
.IX Item "Failed %d/%d tests, %.2f%% okay. %s"
.PD
If not all tests were successful, the script dies with one of the
above messages.
.ie n .IP """FAILED\-\-Further testing stopped: %s""" 4
.el .IP "\f(CWFAILED\-\-Further testing stopped: %s\fR" 4
.IX Item "FAILED--Further testing stopped: %s"
If a single subtest decides that further testing will not make sense,
the script dies with this message.
.SH "ENVIRONMENT"
.IX Header "ENVIRONMENT"
.ie n .IP """HARNESS_ACTIVE""" 4
.el .IP "\f(CWHARNESS_ACTIVE\fR" 4
.IX Item "HARNESS_ACTIVE"
Harness sets this before executing the individual tests. This allows
the tests to determine if they are being executed through the harness
or by any other means.
.ie n .IP """HARNESS_COLUMNS""" 4
.el .IP "\f(CWHARNESS_COLUMNS\fR" 4
.IX Item "HARNESS_COLUMNS"
This value will be used for the width of the terminal. If it is not
set then it will default to \f(CW\*(C`COLUMNS\*(C'\fR. If this is not set, it will
default to 80. Note that users of Bourne-sh based shells will need to
\&\f(CW\*(C`export COLUMNS\*(C'\fR for this module to use that variable.
.ie n .IP """HARNESS_COMPILE_TEST""" 4
.el .IP "\f(CWHARNESS_COMPILE_TEST\fR" 4
.IX Item "HARNESS_COMPILE_TEST"
When true it will make harness attempt to compile the test using
\&\f(CW\*(C`perlcc\*(C'\fR before running it.
.Sp
\&\fB\s-1NOTE\s0\fR This currently only works when sitting in the perl source
directory!
.ie n .IP """HARNESS_FILELEAK_IN_DIR""" 4
.el .IP "\f(CWHARNESS_FILELEAK_IN_DIR\fR" 4
.IX Item "HARNESS_FILELEAK_IN_DIR"
When set to the name of a directory, harness will check after each
test whether new files appeared in that directory, and report them as
.Sp
.Vb 1
\& LEAKED FILES: scr.tmp 0 my.db
.Ve
.Sp
If relative, directory name is with respect to the current directory at
the moment \fIruntests()\fR was called. Putting absolute path into
\&\f(CW\*(C`HARNESS_FILELEAK_IN_DIR\*(C'\fR may give more predictable results.
.ie n .IP """HARNESS_IGNORE_EXITCODE""" 4
.el .IP "\f(CWHARNESS_IGNORE_EXITCODE\fR" 4
.IX Item "HARNESS_IGNORE_EXITCODE"
Makes harness ignore the exit status of child processes when defined.
.ie n .IP """HARNESS_NOTTY""" 4
.el .IP "\f(CWHARNESS_NOTTY\fR" 4
.IX Item "HARNESS_NOTTY"
When set to a true value, forces it to behave as though \s-1STDOUT\s0 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).
.ie n .IP """HARNESS_PERL_SWITCHES""" 4
.el .IP "\f(CWHARNESS_PERL_SWITCHES\fR" 4
.IX Item "HARNESS_PERL_SWITCHES"
Its value will be prepended to the switches used to invoke perl on
each test. For example, setting \f(CW\*(C`HARNESS_PERL_SWITCHES\*(C'\fR to \f(CW\*(C`\-W\*(C'\fR will
run all tests with all warnings enabled.
.ie n .IP """HARNESS_VERBOSE""" 4
.el .IP "\f(CWHARNESS_VERBOSE\fR" 4
.IX Item "HARNESS_VERBOSE"
If true, Test::Harness will output the verbose results of running
its tests. Setting \f(CW$Test::Harness::verbose\fR will override this.
.SH "EXAMPLE"
.IX Header "EXAMPLE"
Here's how Test::Harness tests itself
.PP
.Vb 10
\& $ cd ~/src/devel/Test-Harness
\& $ perl -Mblib -e 'use Test::Harness 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)
.Ve
.SH "SEE ALSO"
.IX Header "SEE ALSO"
Test and Test::Simple for writing test scripts, Benchmark for
the underlying timing routines, Devel::CoreStack to generate core
dumps from failed tests and Devel::Cover for test coverage
analysis.
.SH "AUTHORS"
.IX Header "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 \s-1TEST\s0 script that came
with perl distributions for ages. Numerous anonymous contributors
exist. Andreas Koenig held the torch for many years.
.PP
Current maintainer is Michael G Schwern <schwern@pobox.com>
.SH "TODO"
.IX Header "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 \fIruntests()\fR which rather than printing its output returns raw data
on the state of the tests. (Partially done in Test::Harness::Straps)
.PP
Fix \s-1HARNESS_COMPILE_TEST\s0 without breaking its core usage.
.PP
Figure a way to report test names in the failure summary.
.PP
Rework the test summary so long test names are not truncated as badly.
(Partially done with new skip test styles)
.PP
Deal with \s-1VMS\s0's \*(L"not \enok 4\en\*(R" mistake.
.PP
Add option for coverage analysis.
.SH "BUGS"
.IX Header "BUGS"
\&\s-1HARNESS_COMPILE_TEST\s0 currently assumes it's run from the Perl source
directory.
|