Test::Harness(3pm)
πΈ NAME πΈ
Test::Harness β Run Perl standard test scripts with statistics.
okay bestie, welcome to Test::Harness(3pm) from the Perl Programmers Reference Guide π
π VERSION π
Version 3.50 β that's the vibe check for this page, no cap β¨
β¨ SYNOPSIS β¨
use Test::Harness;
runtests(@test_files);
π DESCRIPTION π
okay so, for historical reasons, the Test::Harness distribution takes its name from this module, but it now exists only to provide TAP::Harness with an interface that is somewhat backwards compatible with Test::Harness 2.xx. If you're writing new code, consider using TAP::Harness directly instead β main character energy, honestly π«Ά
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.
See TAP::Parser, TAP::Harness for the main documentation for this distribution.
π§ͺ FUNCTIONS π§ͺ
The following functions are available, bestie:
π§ͺ runtests( @test_files ) π§ͺ
This runs all the given @test_files and divines whether they passed or failed based on their output to STDOUT (details above β yes, it says above, we don't ask questions π). It prints out each individual test which failed along with a summary report and how long it all took.
It returns true if everything was ok. Otherwise it will die() with one of the messages in the DIAGNOSTICS section.
π§ͺ execute_tests( tests => \@test_files, out => \*FH ) π§ͺ
Runs all the given @test_files (just like runtests()) but doesn't generate the final report. 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 passedmaxβ 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. slay π
$failed is a hash ref of all the test scripts that failed. Each key is the name of a test script, 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 string).
$failed should be empty if everything passed. clean vibes only β¨
π«Ά EXPORT π«Ά
&runtests is exported by Test::Harness by default.
&execute_tests, $verbose, $switches and $debug are exported upon request.
π ENVIRONMENT VARIABLES THAT TAP::HARNESS::COMPATIBLE SETS π
Test::Harness sets these before executing the individual tests.
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.HARNESS_VERSIONβ This is the version ofTest::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 }.
HARNESS_TIMERβ Setting this to true will make the harness display the number of milliseconds each test took. You can also use prove's--timerswitch.HARNESS_VERBOSEβ If true,Test::Harnesswill output the verbose results of running its tests. Setting$Test::Harness::verbosewill override this, or you can use the-vswitch in the prove utility.HARNESS_OPTIONSβ Provide additional options to the harness. Currently supported options are:j<n>β Run<n>(default 9) parallel jobs.cβ Try to color output. SeenewinTAP::Formatter::Base.a<file.tgz>β Will useTAP::Harness::Archiveas the harness class, and save the TAP tofile.tgzfPackage-With-Dashesβ Set theformatter_classof the harness being run. Since theHARNESS_OPTIONSis separated by:, we use-instead.
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. iconic behaviour, honestly π
π 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.
π 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 F<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.
π 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.
okay this page is out β source/version perl v5.42.3, stamped 2026-11-03, and still serving Test::Harness(3pm) to the very end. bye bestie π«Άβ¨
π¦ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms