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 ran
  • ok โ€” number of individual tests passed
  • sub_skipped โ€” number of individual tests skipped
  • todo โ€” number of individual todo tests
  • files โ€” number of test files ran
  • good โ€” number of test files passed
  • bad โ€” number of test files failed
  • tests โ€” number of test files originally given
  • skipped โ€” 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 failed
  • estat โ€” script's exit value
  • wstat โ€” script's wait status
  • max โ€” number of individual tests
  • failed โ€” number which failed
  • canon โ€” list of tests which failed (as a string)

$failed should be empty if everything passed. empty = the dream ๐ŸŒธ


๐ŸŽ€ EXPORT ๐ŸŽ€

  • &runtests is exported by "Test::Harness" by default. she comes free with the meal ๐Ÿ’–
  • &execute_tests, $verbose, $switches and $debug are 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::verbose will 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" in TAP::Formatter::Base.
    • "a<file.tgz>" โ€” will use TAP::Harness::Archive as the harness class, and save the TAP to "file.tgz"
    • "fPackage-With-Dashes" โ€” set the formatter_class of 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 a TAP::Harness subclass to be used in place of TAP::Harness.
  • "HARNESS_SUMMARY_COLOR_SUCCESS" โ€” determines the Term::ANSIColor for the summary in case it is successful. This color defaults to 'green' ๐Ÿ’š
  • "HARNESS_SUMMARY_COLOR_FAIL" โ€” determines the Term::ANSIColor for 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 ๐Ÿ”ฅ


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