.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 .\" .\" 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 "2001-09-21" "perl v5.8.8" "Perl Programmers Reference Guide" .SH "NAME" Test::Harness \- Run Perl standard test scripts with statistics .SH "VERSION" .IX Header "VERSION" Version 2.56 .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. Test::Harness 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::Harness to use those modules. .PP Test::Harness runs tests and expects output from the test in a certain format. That format is called \s-1TAP\s0, the Test Anything Protocol. It is defined in Test::Harness::TAP. .PP \&\f(CW\*(C`Test::Harness::runtests(@tests)\*(C'\fR runs all the testscripts named as arguments and checks standard output for the expected strings in \s-1TAP\s0 format. .PP The \fIprove\fR utility is a thin wrapper around Test::Harness. .Sh "Taint mode" .IX Subsection "Taint mode" Test::Harness will honor the \f(CW\*(C`\-T\*(C'\fR or \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. .ie n .IP "$Test::Harness::Verbose" 4 .el .IP "\f(CW$Test::Harness::Verbose\fR" 4 .IX Item "$Test::Harness::Verbose" The package variable \f(CW$Test::Harness::Verbose\fR is exportable and can be used to let \f(CW\*(C`runtests()\*(C'\fR display the standard output of the script without altering the behavior otherwise. The \fIprove\fR utility's \f(CW\*(C`\-v\*(C'\fR flag will set this. .ie n .IP "$Test::Harness::switches" 4 .el .IP "\f(CW$Test::Harness::switches\fR" 4 .IX Item "$Test::Harness::switches" The package 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. It overrides \f(CW\*(C`HARNESS_SWITCHES\*(C'\fR. .ie n .IP "$Test::Harness::Timer" 4 .el .IP "\f(CW$Test::Harness::Timer\fR" 4 .IX Item "$Test::Harness::Timer" If set to true, and \f(CW\*(C`Time::HiRes\*(C'\fR is available, print elapsed seconds after each test file. .Sh "Failure" .IX Subsection "Failure" When tests fail, analyze 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 \fIt/waterloo.t\fR. 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. .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 \fI@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 \f(CW\*(C`die()\*(C'\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 by default. .PP \&\f(CW$verbose\fR, \f(CW$switches\fR and \f(CW$debug\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 VARIABLES THAT TEST::HARNESS SETS" .IX Header "ENVIRONMENT VARIABLES THAT TEST::HARNESS SETS" Test::Harness sets these before executing the individual tests. .ie n .IP """HARNESS_ACTIVE""" 4 .el .IP "\f(CWHARNESS_ACTIVE\fR" 4 .IX Item "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. .ie n .IP """HARNESS_VERSION""" 4 .el .IP "\f(CWHARNESS_VERSION\fR" 4 .IX Item "HARNESS_VERSION" This is the version of Test::Harness. .SH "ENVIRONMENT VARIABLES THAT AFFECT TEST::HARNESS" .IX Header "ENVIRONMENT VARIABLES THAT AFFECT TEST::HARNESS" .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_DEBUG""" 4 .el .IP "\f(CWHARNESS_DEBUG\fR" 4 .IX Item "HARNESS_DEBUG" If true, Test::Harness will print debugging information about itself as it runs the tests. This is different from \f(CW\*(C`HARNESS_VERBOSE\*(C'\fR, which prints the output from the test being run. Setting \f(CW$Test::Harness::Debug\fR will override this, or you can use the \f(CW\*(C`\-d\*(C'\fR switch in the \fIprove\fR utility. .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""" 4 .el .IP "\f(CWHARNESS_PERL\fR" 4 .IX Item "HARNESS_PERL" Usually your tests will be run by \f(CW$^X\fR, 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. .Sp If you're using the \fIprove\fR utility, you can use the \f(CW\*(C`\-\-perl\*(C'\fR switch. .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, or you can use the \f(CW\*(C`\-v\*(C'\fR switch in the \fIprove\fR utility. .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" The included \fIprove\fR 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. .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 Document the format. .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 Add option for coverage analysis. .PP Trap \s-1STDERR\s0. .PP Implement Straps \fItotal_results()\fR .PP Remember exit code .PP Completely redo the print summary code. .PP Implement Straps callbacks. (experimentally implemented) .PP Straps\->\fIanalyze_file()\fR not taint clean, don't know if it can be .PP Fix that damned \s-1VMS\s0 nit. .PP \&\s-1HARNESS_TODOFAIL\s0 to display \s-1TODO\s0 failures .PP Add a test for verbose. .PP Change internal list of test results to a hash. .PP Fix stats display when there's an overrun. .PP Fix so perls with spaces in the filename work. .PP Keeping whittling away at \fI_run_all_tests()\fR .PP Clean up how the summary is printed. Get rid of those damned formats. .SH "BUGS" .IX Header "BUGS" \&\s-1HARNESS_COMPILE_TEST\s0 currently assumes it's run from the Perl source directory. .PP Please use the \s-1CPAN\s0 bug ticketing system at . You can also mail bugs, fixes and enhancements to \&\f(CW\*(C`\*(C'\fR. .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, and then Michael G Schwern. .PP Current maintainer is Andy Lester \f(CW\*(C`\*(C'\fR. .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright 2002\-2005 by Michael G Schwern \f(CW\*(C`\*(C'\fR, Andy Lester \f(CW\*(C`\*(C'\fR. .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .PP See .