Test::Harness(3perl)
๐ Test::Harness โ bestie, come get your test runner ๐
okay so this is Test::Harness(3perl), straight out of the Perl Programmers Reference Guide, and she's living in Test::Harness version 3.52. Let's get into it ๐
โจ NAME โจ
Test::Harness โ run Perl standard test scripts with stats. yes, statistics. she's keeping receipts ๐
๐ฆ VERSION ๐ฆ
Version 3.52. that's the one. slay.
๐ธ SYNOPSIS ๐ธ
use Test::Harness;
runtests(@test_files);
๐ DESCRIPTION ๐
so here's the tea, and it's a little historical-narrative-shaped so stay with me ๐ซถ
Even though โ for historical reasons, which is code for "it's complicated, don't ask" โ the whole Test::Harness distribution takes its name from this module, this module now exists only to provide TAP::Harness with an interface that's somewhat backwards compatible with Test::Harness 2.xx. So she's basically a legacy queen doing a nostalgia tour ๐
If you're writing new code, bestie, consider using TAP::Harness directly instead. no cap, just go to the source.
Emulation is provided for "runtests" and "execute_tests" โ but the pluggable 'Straps' interface that previous versions of Test::Harness supported is not reproduced here ๐. Straps is now available as a stand alone module: Test::Harness::Straps. so if you came here looking for Straps, she moved out, she has her own place now.
See TAP::Parser, TAP::Harness for the main documentation for this distribution. that's where the real lore lives โจ
๐ฅ FUNCTIONS ๐ฅ
The following functions are available. only these two, and honestly? they ate.
๐ runtests( @test_files )
This runs all the given @test_files and divines (yes, divines, like a little oracle ๐ฎ) 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 did all of that take" number โฑ๏ธ
It returns true if everything was ok โ
Otherwise it will die() with one of the messages in the DIAGNOSTICS section. so like, it doesn't just ghost you โ it tells you what went wrong.
๐ execute_tests( tests => \@test_files, out => \*FH )
Runs all the given @test_files โ just like runtests() โ but doesn't generate the final report. Basically all the grinding, none of the recap. During testing, progress information will be written to the currently selected output filehandle (usually "STDOUT"), or to the filehandle given by the "out" parameter. The out is optional.
Returns a list of two values, $total and $failed, describing the results.
$total is a hash ref summary of all the tests run. Its keys and values are this:
bonusโ number of individual todo tests unexpectedly passed ๐ญ (the good surprises)maxโ number of individual tests ranokโ number of individual tests passedsub_skippedโ number of individual tests skippedtodoโ number of individual todo testsfilesโ number of test files rangoodโ number of test files passedbadโ number of test files failedtestsโ number of test files originally givenskippedโ number of test files skipped
If "$total->{bad} == 0" and "$total->{max} > 0", you've got a successful test. that's the vibe check passing โจ
$failed is a hash ref of all the test scripts that failed. Each key is the name of a test script, and each value is another hash representing how that script failed ๐ Its keys are these:
nameโ name of the test which failedestatโ script's exit valuewstatโ script's wait statusmaxโ number of individual testsfailedโ number which failedcanonโ list of tests which failed (as a string)
$failed should be empty if everything passed. empty = the dream ๐ธ
๐ EXPORT ๐
&runtestsis exported by"Test::Harness"by default. she comes free with the meal ๐&execute_tests,$verbose,$switchesand$debugare exported upon request. you gotta ask nicely.
๐ ENVIRONMENT VARIABLES THAT TAP::HARNESS::COMPATIBLE SETS ๐
"Test::Harness" sets these before executing the individual tests. so they're already there when your test wakes up.
"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. it's the "am I in the group chat or not" flag ๐ซถ"HARNESS_VERSION"โ this is the version of"Test::Harness".
๐ ENVIRONMENT VARIABLES THAT AFFECT TEST::HARNESS ๐
"HARNESS_PERL_SWITCHES"โ setting this adds perl command line switches to each test file run.
For example, "HARNESS_PERL_SWITCHES=-T" will turn on taint mode. "HARNESS_PERL_SWITCHES=-MDevel::Cover" will run "Devel::Cover" for each test.
"-w" is always set. You can turn this off in the test with "BEGIN { $^W = 0 }". she's on by default, but you can mute her ๐
"HARNESS_TIMER"โ setting this to true will make the harness display the number of milliseconds each test took โฑ๏ธ You can also use prove's"--timer"switch."HARNESS_VERBOSE"โ if true,"Test::Harness"will output the verbose results of running its tests. Setting$Test::Harness::verbosewill override this, or you can use the"-v"switch in the prove utility."HARNESS_OPTIONS"โ provide additional options to the harness. Currently supported options are:"j<n>"โ run<n>(default 9) parallel jobs. multitasking icon ๐"c"โ try to color output. See"new"inTAP::Formatter::Base."a<file.tgz>"โ will useTAP::Harness::Archiveas the harness class, and save the TAP to"file.tgz""fPackage-With-Dashes"โ set theformatter_classof the harness being run. Since the"HARNESS_OPTIONS"is separated by":", we use"-"instead. sneaky but correct ๐
Multiple options may be separated by colons:
HARNESS_OPTIONS=j9:c make test
"HARNESS_SUBCLASS"โ specifies aTAP::Harnesssubclass to be used in place ofTAP::Harness."HARNESS_SUMMARY_COLOR_SUCCESS"โ determines theTerm::ANSIColorfor the summary in case it is successful. This color defaults to'green'๐"HARNESS_SUMMARY_COLOR_FAIL"โ determines theTerm::ANSIColorfor the failure in case it is successful. This color defaults to'red'โค๏ธ
๐ Taint Mode ๐
Normally when a Perl program is run in taint mode the contents of the "PERL5LIB" environment variable do not appear in @INC.
Because "PERL5LIB" is often used during testing to add build directories to @INC, "Test::Harness" passes the names of any directories found in "PERL5LIB" as -I switches. The net effect of this is that "PERL5LIB" is honoured even in taint mode. she said "not on my watch" ๐ก๏ธโจ
๐ SEE ALSO ๐
TAP::Harness
๐ BUGS ๐
Please report any bugs or feature requests to bug-test-harness at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Harness. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. so you're not shouting into the void, bestie, the notifications go both ways ๐ซถ
๐ง AUTHORS ๐ง
Andy Armstrong <andy@hexten.net>
Test::Harness 2.64 (maintained by Andy Lester and on which this module is based) has this attribution:
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.
carrying the torch for years and years? that's legacy main character energy, fr fr ๐ฅ
โญ LICENCE AND COPYRIGHT โญ
Copyright (c) 2007-2011, Andy Armstrong "<andy@hexten.net>". All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic. free as in do-what-you-want-with-the-legalities ๐
and that's the whole page, bestie ๐ this was perl v5.44.0, dated 2026-10-17, and she goes by Test::Harness(3perl). periodt ๐
โจ
๐ฆ where this page comes from
- arch rolling: perl 5.44.0-1 ยท Artistic-1.0-Perl AND GPL-1.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms