1Test::Harness(3pm)     Perl Programmers Reference Guide     Test::Harness(3pm)
2
3
4

NAME

6       Test::Harness - Run Perl standard test scripts with statistics
7

VERSION

9       Version 2.56
10

SYNOPSIS

12         use Test::Harness;
13
14         runtests(@test_files);
15

DESCRIPTION

17       STOP! If all you want to do is write a test script, consider using
18       Test::Simple.  Test::Harness is the module that reads the output from
19       Test::Simple, Test::More and other modules based on Test::Builder.  You
20       don't need to know about Test::Harness to use those modules.
21
22       Test::Harness runs tests and expects output from the test in a certain
23       format.  That format is called TAP, the Test Anything Protocol.  It is
24       defined in Test::Harness::TAP.
25
26       "Test::Harness::runtests(@tests)" runs all the testscripts named as
27       arguments and checks standard output for the expected strings in TAP
28       format.
29
30       The prove utility is a thin wrapper around Test::Harness.
31
32       Taint mode
33
34       Test::Harness will honor the "-T" or "-t" in the #! line on your test
35       files.  So if you begin a test with:
36
37           #!perl -T
38
39       the test will be run with taint mode on.
40
41       Configuration variables.
42
43       These variables can be used to configure the behavior of Test::Harness.
44       They are exported on request.
45
46       $Test::Harness::Verbose
47           The package variable $Test::Harness::Verbose is exportable and can
48           be used to let "runtests()" display the standard output of the
49           script without altering the behavior otherwise.  The prove util‐
50           ity's "-v" flag will set this.
51
52       $Test::Harness::switches
53           The package variable $Test::Harness::switches is exportable and can
54           be used to set perl command line options used for running the test
55           script(s). The default value is "-w". It overrides "HAR‐
56           NESS_SWITCHES".
57
58       $Test::Harness::Timer
59           If set to true, and "Time::HiRes" is available, print elapsed sec‐
60           onds after each test file.
61
62       Failure
63
64       When tests fail, analyze the summary report:
65
66         t/base..............ok
67         t/nonumbers.........ok
68         t/ok................ok
69         t/test-harness......ok
70         t/waterloo..........dubious
71                 Test returned status 3 (wstat 768, 0x300)
72         DIED. FAILED tests 1, 3, 5, 7, 9, 11, 13, 15, 17, 19
73                 Failed 10/20 tests, 50.00% okay
74         Failed Test  Stat Wstat Total Fail  Failed  List of Failed
75         -----------------------------------------------------------------------
76         t/waterloo.t    3   768    20   10  50.00%  1 3 5 7 9 11 13 15 17 19
77         Failed 1/5 test scripts, 80.00% okay. 10/44 subtests failed, 77.27% okay.
78
79       Everything passed but t/waterloo.t.  It failed 10 of 20 tests and
80       exited with non-zero status indicating something dubious happened.
81
82       The columns in the summary report mean:
83
84       Failed Test
85           The test file which failed.
86
87       Stat
88           If the test exited with non-zero, this is its exit status.
89
90       Wstat
91           The wait status of the test.
92
93       Total
94           Total number of tests expected to run.
95
96       Fail
97           Number which failed, either from "not ok" or because they never
98           ran.
99
100       Failed
101           Percentage of the total tests which failed.
102
103       List of Failed
104           A list of the tests which failed.  Successive failures may be
105           abbreviated (ie. 15-20 to indicate that tests 15, 16, 17, 18, 19
106           and 20 failed).
107
108       Functions
109
110       Test::Harness currently only has one function, here it is.
111
112       runtests
113             my $allok = runtests(@test_files);
114
115           This runs all the given @test_files and divines whether they passed
116           or failed based on their output to STDOUT (details above).  It
117           prints out each individual test which failed along with a summary
118           report and a how long it all took.
119
120           It returns true if everything was ok.  Otherwise it will "die()"
121           with one of the messages in the DIAGNOSTICS section.
122

EXPORT

124       &runtests is exported by Test::Harness by default.
125
126       $verbose, $switches and $debug are exported upon request.
127

DIAGNOSTICS

129       "All tests successful.\nFiles=%d,  Tests=%d, %s"
130           If all tests are successful some statistics about the performance
131           are printed.
132
133       "FAILED tests %s\n\tFailed %d/%d tests, %.2f%% okay."
134           For any single script that has failing subtests statistics like the
135           above are printed.
136
137       "Test returned status %d (wstat %d)"
138           Scripts that return a non-zero exit status, both "$? >> 8" and $?
139           are printed in a message similar to the above.
140
141       "Failed 1 test, %.2f%% okay. %s"
142       "Failed %d/%d tests, %.2f%% okay. %s"
143           If not all tests were successful, the script dies with one of the
144           above messages.
145
146       "FAILED--Further testing stopped: %s"
147           If a single subtest decides that further testing will not make
148           sense, the script dies with this message.
149

ENVIRONMENT VARIABLES THAT TEST::HARNESS SETS

151       Test::Harness sets these before executing the individual tests.
152
153       "HARNESS_ACTIVE"
154           This is set to a true value.  It allows the tests to determine if
155           they are being executed through the harness or by any other means.
156
157       "HARNESS_VERSION"
158           This is the version of Test::Harness.
159

ENVIRONMENT VARIABLES THAT AFFECT TEST::HARNESS

161       "HARNESS_COLUMNS"
162           This value will be used for the width of the terminal. If it is not
163           set then it will default to "COLUMNS". If this is not set, it will
164           default to 80. Note that users of Bourne-sh based shells will need
165           to "export COLUMNS" for this module to use that variable.
166
167       "HARNESS_COMPILE_TEST"
168           When true it will make harness attempt to compile the test using
169           "perlcc" before running it.
170
171           NOTE This currently only works when sitting in the perl source
172           directory!
173
174       "HARNESS_DEBUG"
175           If true, Test::Harness will print debugging information about
176           itself as it runs the tests.  This is different from "HARNESS_VER‐
177           BOSE", which prints the output from the test being run.  Setting
178           $Test::Harness::Debug will override this, or you can use the "-d"
179           switch in the prove utility.
180
181       "HARNESS_FILELEAK_IN_DIR"
182           When set to the name of a directory, harness will check after each
183           test whether new files appeared in that directory, and report them
184           as
185
186             LEAKED FILES: scr.tmp 0 my.db
187
188           If relative, directory name is with respect to the current direc‐
189           tory at the moment runtests() was called.  Putting absolute path
190           into "HARNESS_FILELEAK_IN_DIR" may give more predictable results.
191
192       "HARNESS_IGNORE_EXITCODE"
193           Makes harness ignore the exit status of child processes when
194           defined.
195
196       "HARNESS_NOTTY"
197           When set to a true value, forces it to behave as though STDOUT were
198           not a console.  You may need to set this if you don't want harness
199           to output more frequent progress messages using carriage returns.
200           Some consoles may not handle carriage returns properly (which
201           results in a somewhat messy output).
202
203       "HARNESS_PERL"
204           Usually your tests will be run by $^X, the currently-executing
205           Perl.  However, you may want to have it run by a different exe‐
206           cutable, such as a threading perl, or a different version.
207
208           If you're using the prove utility, you can use the "--perl" switch.
209
210       "HARNESS_PERL_SWITCHES"
211           Its value will be prepended to the switches used to invoke perl on
212           each test.  For example, setting "HARNESS_PERL_SWITCHES" to "-W"
213           will run all tests with all warnings enabled.
214
215       "HARNESS_VERBOSE"
216           If true, Test::Harness will output the verbose results of running
217           its tests.  Setting $Test::Harness::verbose will override this, or
218           you can use the "-v" switch in the prove utility.
219

EXAMPLE

221       Here's how Test::Harness tests itself
222
223         $ cd ~/src/devel/Test-Harness
224         $ perl -Mblib -e 'use Test::Harness qw(&runtests $verbose);
225           $verbose=0; runtests @ARGV;' t/*.t
226         Using /home/schwern/src/devel/Test-Harness/blib
227         t/base..............ok
228         t/nonumbers.........ok
229         t/ok................ok
230         t/test-harness......ok
231         All tests successful.
232         Files=4, Tests=24, 2 wallclock secs ( 0.61 cusr + 0.41 csys = 1.02 CPU)
233

SEE ALSO

235       The included prove utility for running test scripts from the command
236       line, Test and Test::Simple for writing test scripts, Benchmark for the
237       underlying timing routines, and Devel::Cover for test coverage analy‐
238       sis.
239

TODO

241       Provide a way of running tests quietly (ie. no printing) for automated
242       validation of tests.  This will probably take the form of a version of
243       runtests() which rather than printing its output returns raw data on
244       the state of the tests.  (Partially done in Test::Harness::Straps)
245
246       Document the format.
247
248       Fix HARNESS_COMPILE_TEST without breaking its core usage.
249
250       Figure a way to report test names in the failure summary.
251
252       Rework the test summary so long test names are not truncated as badly.
253       (Partially done with new skip test styles)
254
255       Add option for coverage analysis.
256
257       Trap STDERR.
258
259       Implement Straps total_results()
260
261       Remember exit code
262
263       Completely redo the print summary code.
264
265       Implement Straps callbacks.  (experimentally implemented)
266
267       Straps->analyze_file() not taint clean, don't know if it can be
268
269       Fix that damned VMS nit.
270
271       HARNESS_TODOFAIL to display TODO failures
272
273       Add a test for verbose.
274
275       Change internal list of test results to a hash.
276
277       Fix stats display when there's an overrun.
278
279       Fix so perls with spaces in the filename work.
280
281       Keeping whittling away at _run_all_tests()
282
283       Clean up how the summary is printed.  Get rid of those damned formats.
284

BUGS

286       HARNESS_COMPILE_TEST currently assumes it's run from the Perl source
287       directory.
288
289       Please use the CPAN bug ticketing system at <http://rt.cpan.org/>.  You
290       can also mail bugs, fixes and enhancements to "<bug-test-harness" at
291       "rt.cpan.org>".
292

AUTHORS

294       Either Tim Bunce or Andreas Koenig, we don't know. What we know for
295       sure is, that it was inspired by Larry Wall's TEST script that came
296       with perl distributions for ages. Numerous anonymous contributors
297       exist.  Andreas Koenig held the torch for many years, and then Michael
298       G Schwern.
299
300       Current maintainer is Andy Lester "<andy at petdance.com>".
301
303       Copyright 2002-2005 by Michael G Schwern "<schwern at pobox.com>", Andy
304       Lester "<andy at petdance.com>".
305
306       This program is free software; you can redistribute it and/or modify it
307       under the same terms as Perl itself.
308
309       See <http://www.perl.com/perl/misc/Artistic.html>.
310
311
312
313perl v5.8.8                       2001-09-21                Test::Harness(3pm)
Impressum