CINXE.COM

TAP::Harness - Run test scripts with statistics - Perldoc Browser

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>TAP::Harness - Run test scripts with statistics - Perldoc Browser</title> <link rel="search" href="/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser"> <link rel="canonical" href="https://perldoc.perl.org/TAP::Harness"> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" /> <style> body { background: #f4f4f5; color: #020202; } .navbar-dark { background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%); background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%); background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%); filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0); background-repeat: repeat-x; } .navbar-dark .navbar-nav .nav-link, .navbar-dark .navbar-nav .nav-link:focus { color: #fff } .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 } #wrapperlicious { margin: 0 auto; font: 0.9em 'Helvetica Neue', Helvetica, sans-serif; font-weight: normal; line-height: 1.5em; margin: 0; padding: 0; } #wrapperlicious h1 { font-size: 1.5em } #wrapperlicious h2 { font-size: 1.3em } #wrapperlicious h3 { font-size: 1.1em } #wrapperlicious h4 { font-size: 0.9em } #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3, #wrapperlicious h4, #wrapperlicious dt { color: #020202; margin-top: 1em; margin-bottom: 1em; position: relative; font-weight: bold; } #wrapperlicious a { color: inherit; text-decoration: underline } #wrapperlicious #toc { text-decoration: none } #wrapperlicious a:hover { color: #2a2a2a } #wrapperlicious a img { border: 0 } #wrapperlicious :not(pre) > code { color: inherit; background-color: rgba(0, 0, 0, 0.04); border-radius: 3px; font: 0.9em Consolas, Menlo, Monaco, monospace; padding: 0.3em; } #wrapperlicious dd { margin: 0; margin-left: 2em; } #wrapperlicious dt { color: #2a2a2a; font-weight: bold; margin-left: 0.9em; } #wrapperlicious p { margin-bottom: 1em; margin-top: 1em; } #wrapperlicious li > p { margin-bottom: 0; margin-top: 0; } #wrapperlicious pre { border: 1px solid #c1c1c1; border-radius: 3px; font: 100% Consolas, Menlo, Monaco, monospace; margin-bottom: 1em; margin-top: 1em; } #wrapperlicious pre > code { display: block; background-color: #f6f6f6; font: 0.9em Consolas, Menlo, Monaco, monospace; line-height: 1.5em; text-align: left; white-space: pre; padding: 1em; } #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul { margin-bottom: 1em; margin-top: 1em; } #wrapperlicious ul { list-style-type: square; } #wrapperlicious ul ul { margin-bottom: 0px; margin-top: 0px; } #footer { font-size: 0.8em; padding-top: 0.5em; text-align: center; } #more { display: inline; font-size: 0.8em; } #perldocdiv { background-color: #fff; border: 1px solid #c1c1c1; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; margin-left: auto; margin-right: auto; padding: 3em; padding-top: 1em; max-width: 960px; } #moduleversion { float: right } #wrapperlicious .leading-notice { font-style: italic; padding-left: 1em; margin-top: 1em; margin-bottom: 1em; } #wrapperlicious .permalink { display: none; left: -0.75em; position: absolute; padding-right: 0.25em; text-decoration: none; } #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink, #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink, #wrapperlicious dt:hover .permalink { display: block; } </style> <!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-KVNWBNT5FB'); gtag('config', 'UA-50555-3'); </script> </head> <body> <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <a class="navbar-brand" href="/"><img src="/images/perl_camel_30.png" width="30" height="30" class="d-inline-block align-top" alt="Perl Camel Logo"> Perldoc Browser</a> <div class="collapse navbar-collapse" id="navbarNav"> <ul class="navbar-nav mr-auto"> <li class="nav-item dropdown text-nowrap"> <a class="nav-link dropdown-toggle" href="#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.12.1</a> <div class="dropdown-menu" aria-labelledby="dropdownlink-stable"> <a class="dropdown-item" href="/TAP::Harness">Latest</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.40.1/TAP::Harness">5.40.1</a> <a class="dropdown-item" href="/5.40.0/TAP::Harness">5.40.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.38.3/TAP::Harness">5.38.3</a> <a class="dropdown-item" href="/5.38.2/TAP::Harness">5.38.2</a> <a class="dropdown-item" href="/5.38.1/TAP::Harness">5.38.1</a> <a class="dropdown-item" href="/5.38.0/TAP::Harness">5.38.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.36.3/TAP::Harness">5.36.3</a> <a class="dropdown-item" href="/5.36.2/TAP::Harness">5.36.2</a> <a class="dropdown-item" href="/5.36.1/TAP::Harness">5.36.1</a> <a class="dropdown-item" href="/5.36.0/TAP::Harness">5.36.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.34.3/TAP::Harness">5.34.3</a> <a class="dropdown-item" href="/5.34.2/TAP::Harness">5.34.2</a> <a class="dropdown-item" href="/5.34.1/TAP::Harness">5.34.1</a> <a class="dropdown-item" href="/5.34.0/TAP::Harness">5.34.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.32.1/TAP::Harness">5.32.1</a> <a class="dropdown-item" href="/5.32.0/TAP::Harness">5.32.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.30.3/TAP::Harness">5.30.3</a> <a class="dropdown-item" href="/5.30.2/TAP::Harness">5.30.2</a> <a class="dropdown-item" href="/5.30.1/TAP::Harness">5.30.1</a> <a class="dropdown-item" href="/5.30.0/TAP::Harness">5.30.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.28.3/TAP::Harness">5.28.3</a> <a class="dropdown-item" href="/5.28.2/TAP::Harness">5.28.2</a> <a class="dropdown-item" href="/5.28.1/TAP::Harness">5.28.1</a> <a class="dropdown-item" href="/5.28.0/TAP::Harness">5.28.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.26.3/TAP::Harness">5.26.3</a> <a class="dropdown-item" href="/5.26.2/TAP::Harness">5.26.2</a> <a class="dropdown-item" href="/5.26.1/TAP::Harness">5.26.1</a> <a class="dropdown-item" href="/5.26.0/TAP::Harness">5.26.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.24.4/TAP::Harness">5.24.4</a> <a class="dropdown-item" href="/5.24.3/TAP::Harness">5.24.3</a> <a class="dropdown-item" href="/5.24.2/TAP::Harness">5.24.2</a> <a class="dropdown-item" href="/5.24.1/TAP::Harness">5.24.1</a> <a class="dropdown-item" href="/5.24.0/TAP::Harness">5.24.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.22.4/TAP::Harness">5.22.4</a> <a class="dropdown-item" href="/5.22.3/TAP::Harness">5.22.3</a> <a class="dropdown-item" href="/5.22.2/TAP::Harness">5.22.2</a> <a class="dropdown-item" href="/5.22.1/TAP::Harness">5.22.1</a> <a class="dropdown-item" href="/5.22.0/TAP::Harness">5.22.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.20.3/TAP::Harness">5.20.3</a> <a class="dropdown-item" href="/5.20.2/TAP::Harness">5.20.2</a> <a class="dropdown-item" href="/5.20.1/TAP::Harness">5.20.1</a> <a class="dropdown-item" href="/5.20.0/TAP::Harness">5.20.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.18.4/TAP::Harness">5.18.4</a> <a class="dropdown-item" href="/5.18.3/TAP::Harness">5.18.3</a> <a class="dropdown-item" href="/5.18.2/TAP::Harness">5.18.2</a> <a class="dropdown-item" href="/5.18.1/TAP::Harness">5.18.1</a> <a class="dropdown-item" href="/5.18.0/TAP::Harness">5.18.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.16.3/TAP::Harness">5.16.3</a> <a class="dropdown-item" href="/5.16.2/TAP::Harness">5.16.2</a> <a class="dropdown-item" href="/5.16.1/TAP::Harness">5.16.1</a> <a class="dropdown-item" href="/5.16.0/TAP::Harness">5.16.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.14.4/TAP::Harness">5.14.4</a> <a class="dropdown-item" href="/5.14.3/TAP::Harness">5.14.3</a> <a class="dropdown-item" href="/5.14.2/TAP::Harness">5.14.2</a> <a class="dropdown-item" href="/5.14.1/TAP::Harness">5.14.1</a> <a class="dropdown-item" href="/5.14.0/TAP::Harness">5.14.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.12.5/TAP::Harness">5.12.5</a> <a class="dropdown-item" href="/5.12.4/TAP::Harness">5.12.4</a> <a class="dropdown-item" href="/5.12.3/TAP::Harness">5.12.3</a> <a class="dropdown-item" href="/5.12.2/TAP::Harness">5.12.2</a> <a class="dropdown-item active" href="/5.12.1/TAP::Harness">5.12.1</a> <a class="dropdown-item" href="/5.12.0/TAP::Harness">5.12.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.10.1/TAP::Harness">5.10.1</a> <a class="dropdown-item" href="/5.10.0/TAP::Harness">5.10.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.8.9/TAP::Harness">5.8.9</a> <a class="dropdown-item" href="/5.8.8/TAP::Harness">5.8.8</a> <a class="dropdown-item" href="/5.8.7/TAP::Harness">5.8.7</a> <a class="dropdown-item" href="/5.8.6/TAP::Harness">5.8.6</a> <a class="dropdown-item" href="/5.8.5/TAP::Harness">5.8.5</a> <a class="dropdown-item" href="/5.8.4/TAP::Harness">5.8.4</a> <a class="dropdown-item" href="/5.8.3/TAP::Harness">5.8.3</a> <a class="dropdown-item" href="/5.8.2/TAP::Harness">5.8.2</a> <a class="dropdown-item" href="/5.8.1/TAP::Harness">5.8.1</a> <a class="dropdown-item" href="/5.8.0/TAP::Harness">5.8.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.6.2/TAP::Harness">5.6.2</a> <a class="dropdown-item" href="/5.6.1/TAP::Harness">5.6.1</a> <a class="dropdown-item" href="/5.6.0/TAP::Harness">5.6.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.005_04/TAP::Harness">5.005_04</a> <a class="dropdown-item" href="/5.005_03/TAP::Harness">5.005_03</a> <a class="dropdown-item" href="/5.005_02/TAP::Harness">5.005_02</a> <a class="dropdown-item" href="/5.005_01/TAP::Harness">5.005_01</a> <a class="dropdown-item" href="/5.005/TAP::Harness">5.005</a> </div> </li> <li class="nav-item dropdown text-nowrap"> <a class="nav-link dropdown-toggle" href="#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a> <div class="dropdown-menu" aria-labelledby="dropdownlink-dev"> <a class="dropdown-item" href="/blead/TAP::Harness">blead</a> <a class="dropdown-item" href="/5.41.10/TAP::Harness">5.41.10</a> <a class="dropdown-item" href="/5.41.9/TAP::Harness">5.41.9</a> <a class="dropdown-item" href="/5.41.8/TAP::Harness">5.41.8</a> <a class="dropdown-item" href="/5.41.7/TAP::Harness">5.41.7</a> <a class="dropdown-item" href="/5.41.6/TAP::Harness">5.41.6</a> <a class="dropdown-item" href="/5.41.5/TAP::Harness">5.41.5</a> <a class="dropdown-item" href="/5.41.4/TAP::Harness">5.41.4</a> <a class="dropdown-item" href="/5.41.3/TAP::Harness">5.41.3</a> <a class="dropdown-item" href="/5.41.2/TAP::Harness">5.41.2</a> <a class="dropdown-item" href="/5.41.1/TAP::Harness">5.41.1</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.40.1-RC1/TAP::Harness">5.40.1-RC1</a> <a class="dropdown-item" href="/5.40.0-RC2/TAP::Harness">5.40.0-RC2</a> <a class="dropdown-item" href="/5.40.0-RC1/TAP::Harness">5.40.0-RC1</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.39.10/TAP::Harness">5.39.10</a> <a class="dropdown-item" href="/5.39.9/TAP::Harness">5.39.9</a> <a class="dropdown-item" href="/5.39.8/TAP::Harness">5.39.8</a> <a class="dropdown-item" href="/5.39.7/TAP::Harness">5.39.7</a> <a class="dropdown-item" href="/5.39.6/TAP::Harness">5.39.6</a> <a class="dropdown-item" href="/5.39.5/TAP::Harness">5.39.5</a> <a class="dropdown-item" href="/5.39.4/TAP::Harness">5.39.4</a> <a class="dropdown-item" href="/5.39.3/TAP::Harness">5.39.3</a> <a class="dropdown-item" href="/5.39.2/TAP::Harness">5.39.2</a> <a class="dropdown-item" href="/5.39.1/TAP::Harness">5.39.1</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.38.3-RC1/TAP::Harness">5.38.3-RC1</a> </div> </li> <li class="nav-item dropdown text-nowrap"> <a class="nav-link dropdown-toggle" href="#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a> <div class="dropdown-menu" aria-labelledby="dropdownlink-nav"> <a class="dropdown-item" href="/5.12.1/perl">Perl</a> <a class="dropdown-item" href="/5.12.1/perlintro">Intro</a> <a class="dropdown-item" href="/5.12.1/perl#Tutorials">Tutorials</a> <a class="dropdown-item" href="/5.12.1/perlfaq">FAQs</a> <a class="dropdown-item" href="/5.12.1/perl#Reference-Manual">Reference</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.12.1/perlop">Operators</a> <a class="dropdown-item" href="/5.12.1/functions">Functions</a> <a class="dropdown-item" href="/5.12.1/variables">Variables</a> <a class="dropdown-item" href="/5.12.1/modules">Modules</a> <a class="dropdown-item" href="/5.12.1/perlutil">Utilities</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.12.1/perldelta">Release Notes</a> <a class="dropdown-item" href="/5.12.1/perlcommunity">Community</a> <a class="dropdown-item" href="/5.12.1/perlhist">History</a> </div> </li> </ul> <ul class="navbar-nav"> <script> function set_expand (expand) { var perldocdiv = document.getElementById('perldocdiv'); var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width'); var expanded = (width == '' || width == 'none') ? true : false; if (expand === null) { expand = !expanded; } if ((expand && !expanded) || (!expand && expanded)) { perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px'); var button_classlist = document.getElementById('content-expand-button').classList; if (expand) { button_classlist.add('btn-light'); button_classlist.remove('btn-outline-light'); } else { button_classlist.add('btn-outline-light'); button_classlist.remove('btn-light'); } } return expand; } function toggle_expand () { var expand = set_expand(null); document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC'; } function read_expand () { return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 }); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', function () { if (read_expand()) { set_expand(true); } }); } else if (read_expand()) { set_expand(true); } </script> <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-4" onclick="toggle_expand()">Expand</button> </ul> <form class="form-inline" method="get" action="/5.12.1/search"> <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search" value=""> </form> </div> </nav> <div id="wrapperlicious" class="container-fluid"> <div id="perldocdiv"> <div id="links"> <a href="/5.12.1/TAP::Harness">TAP::Harness</a> <div id="more"> (<a href="/5.12.1/TAP::Harness.txt">source</a>, <a href="https://metacpan.org/pod/TAP::Harness">CPAN</a>) </div> <div id="moduleversion">version 3.17</div> </div> <div class="leading-notice"> You are viewing the version of this documentation from Perl 5.12.1. <a href="/TAP::Harness">View the latest version</a> </div> <h1><a id="toc">CONTENTS</a></h1> <ul> <li> <a class="text-decoration-none" href="#NAME">NAME</a> </li> <li> <a class="text-decoration-none" href="#VERSION">VERSION</a> </li> <li> <a class="text-decoration-none" href="#DESCRIPTION">DESCRIPTION</a> </li> <li> <a class="text-decoration-none" href="#SYNOPSIS">SYNOPSIS</a> </li> <li> <a class="text-decoration-none" href="#METHODS">METHODS</a> <ul> <li> <a class="text-decoration-none" href="#Class-Methods">Class Methods</a> <ul> <li> <a class="text-decoration-none" href="#new">new</a> </li> </ul> </li> <li> <a class="text-decoration-none" href="#Instance-Methods">Instance Methods</a> <ul> <li> <a class="text-decoration-none" href="#runtests">runtests</a> </li> <li> <a class="text-decoration-none" href="#summary">summary</a> </li> <li> <a class="text-decoration-none" href="#aggregate_tests">aggregate_tests</a> </li> <li> <a class="text-decoration-none" href="#make_scheduler">make_scheduler</a> </li> <li> <a class="text-decoration-none" href="#jobs">jobs</a> </li> </ul> </li> </ul> </li> <li> <a class="text-decoration-none" href="#SUBCLASSING">SUBCLASSING</a> <ul> <li> <a class="text-decoration-none" href="#Methods">Methods</a> <ul> <li> <a class="text-decoration-none" href="#summary1">summary</a> </li> <li> <a class="text-decoration-none" href="#make_parser">make_parser</a> </li> <li> <a class="text-decoration-none" href="#finish_parser">finish_parser</a> </li> </ul> </li> </ul> </li> <li> <a class="text-decoration-none" href="#REPLACING">REPLACING</a> </li> <li> <a class="text-decoration-none" href="#SEE-ALSO">SEE ALSO</a> </li> </ul> <h1 id="NAME"><a class="permalink" href="#NAME">#</a>NAME</h1> <p>TAP::Harness - Run test scripts with statistics</p> <h1 id="VERSION"><a class="permalink" href="#VERSION">#</a>VERSION</h1> <p>Version 3.17</p> <h1 id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">#</a>DESCRIPTION</h1> <p>This is a simple test harness which allows tests to be run and results automatically aggregated and output to STDOUT.</p> <h1 id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">#</a>SYNOPSIS</h1> <pre><code>use TAP::Harness; my $harness = TAP::Harness-&gt;new( \%args ); $harness-&gt;runtests(@tests);</code></pre> <h1 id="METHODS"><a class="permalink" href="#METHODS">#</a>METHODS</h1> <h2 id="Class-Methods"><a class="permalink" href="#Class-Methods">#</a><a id="Class"></a>Class Methods</h2> <h3 id="new"><a class="permalink" href="#new">#</a><code>new</code></h3> <pre><code>my %args = ( verbosity =&gt; 1, lib =&gt; [ &#39;lib&#39;, &#39;blib/lib&#39;, &#39;blib/arch&#39; ], ) my $harness = TAP::Harness-&gt;new( \%args );</code></pre> <p>The constructor returns a new <code>TAP::Harness</code> object. It accepts an optional hashref whose allowed keys are:</p> <ul> <li><p><code>verbosity</code></p> <p>Set the verbosity level:</p> <pre><code class="plaintext"> 1 verbose Print individual test results to STDOUT. 0 normal -1 quiet Suppress some test output (mostly failures while tests are running). -2 really quiet Suppress everything but the tests summary. -3 silent Suppress everything.</code></pre> </li> <li><p><code>timer</code></p> <p>Append run time for each test to output. Uses <a href="/5.12.1/Time::HiRes">Time::HiRes</a> if available.</p> </li> <li><p><code>failures</code></p> <p>Show test failures (this is a no-op if <code>verbose</code> is selected).</p> </li> <li><p><code>comments</code></p> <p>Show test comments (this is a no-op if <code>verbose</code> is selected).</p> </li> <li><p><code>show_count</code></p> <p>Update the running test count during testing.</p> </li> <li><p><code>normalize</code></p> <p>Set to a true value to normalize the TAP that is emitted in verbose modes.</p> </li> <li><p><code>lib</code></p> <p>Accepts a scalar value or array ref of scalar values indicating which paths to allowed libraries should be included if Perl tests are executed. Naturally, this only makes sense in the context of tests written in Perl.</p> </li> <li><p><code>switches</code></p> <p>Accepts a scalar value or array ref of scalar values indicating which switches should be included if Perl tests are executed. Naturally, this only makes sense in the context of tests written in Perl.</p> </li> <li><p><code>test_args</code></p> <p>A reference to an <code>@INC</code> style array of arguments to be passed to each test program.</p> </li> <li><p><code>color</code></p> <p>Attempt to produce color output.</p> </li> <li><p><code>exec</code></p> <p>Typically, Perl tests are run through this. However, anything which spits out TAP is fine. You can use this argument to specify the name of the program (and optional switches) to run your tests with:</p> <pre><code class="plaintext">exec =&gt; [&#39;/usr/bin/ruby&#39;, &#39;-w&#39;]</code></pre> <p>You can also pass a subroutine reference in order to determine and return the proper program to run based on a given test script. The subroutine reference should expect the TAP::Harness object itself as the first argument, and the file name as the second argument. It should return an array reference containing the command to be run and including the test file name. It can also simply return <code>undef</code>, in which case TAP::Harness will fall back on executing the test script in Perl:</p> <pre><code>exec =&gt; sub { my ( $harness, $test_file ) = @_; # Let Perl tests run. return undef if $test_file =~ /[.]t$/; return [ qw( /usr/bin/ruby -w ), $test_file ] if $test_file =~ /[.]rb$/; }</code></pre> <p>If the subroutine returns a scalar with a newline or a filehandle, it will be interpreted as raw TAP or as a TAP stream, respectively.</p> </li> <li><p><code>merge</code></p> <p>If <code>merge</code> is true the harness will create parsers that merge STDOUT and STDERR together for any processes they start.</p> </li> <li><p><code>aggregator_class</code></p> <p>The name of the class to use to aggregate test results. The default is <a href="/5.12.1/TAP::Parser::Aggregator">TAP::Parser::Aggregator</a>.</p> </li> <li><p><code>formatter_class</code></p> <p>The name of the class to use to format output. The default is <a href="/5.12.1/TAP::Formatter::Console">TAP::Formatter::Console</a>, or <a href="/5.12.1/TAP::Formatter::File">TAP::Formatter::File</a> if the output isn&#39;t a TTY.</p> </li> <li><p><code>multiplexer_class</code></p> <p>The name of the class to use to multiplex tests during parallel testing. The default is <a href="/5.12.1/TAP::Parser::Multiplexer">TAP::Parser::Multiplexer</a>.</p> </li> <li><p><code>parser_class</code></p> <p>The name of the class to use to parse TAP. The default is <a href="/5.12.1/TAP::Parser">TAP::Parser</a>.</p> </li> <li><p><code>scheduler_class</code></p> <p>The name of the class to use to schedule test execution. The default is <a href="/5.12.1/TAP::Parser::Scheduler">TAP::Parser::Scheduler</a>.</p> </li> <li><p><code>formatter</code></p> <p>If set <code>formatter</code> must be an object that is capable of formatting the TAP output. See <a href="/5.12.1/TAP::Formatter::Console">TAP::Formatter::Console</a> for an example.</p> </li> <li><p><code>errors</code></p> <p>If parse errors are found in the TAP output, a note of this will be made in the summary report. To see all of the parse errors, set this argument to true:</p> <pre><code class="plaintext">errors =&gt; 1</code></pre> </li> <li><p><code>directives</code></p> <p>If set to a true value, only test results with directives will be displayed. This overrides other settings such as <code>verbose</code> or <code>failures</code>.</p> </li> <li><p><code>ignore_exit</code></p> <p>If set to a true value instruct <code>TAP::Parser</code> to ignore exit and wait status from test scripts.</p> </li> <li><p><code>jobs</code></p> <p>The maximum number of parallel tests to run at any time. Which tests can be run in parallel is controlled by <code>rules</code>. The default is to run only one test at a time.</p> </li> <li><p><code>rules</code></p> <p>A reference to a hash of rules that control which tests may be executed in parallel. This is an experimental feature and the interface may change.</p> <pre><code>$harness-&gt;rules( { par =&gt; [ { seq =&gt; &#39;../ext/DB_File/t/*&#39; }, { seq =&gt; &#39;../ext/IO_Compress_Zlib/t/*&#39; }, { seq =&gt; &#39;../lib/CPANPLUS/*&#39; }, { seq =&gt; &#39;../lib/ExtUtils/t/*&#39; }, &#39;*&#39; ] } );</code></pre> </li> <li><p><code>stdout</code></p> <p>A filehandle for catching standard output.</p> </li> </ul> <p>Any keys for which the value is <code>undef</code> will be ignored.</p> <h2 id="Instance-Methods"><a class="permalink" href="#Instance-Methods">#</a><a id="Instance"></a>Instance Methods</h2> <h3 id="runtests"><a class="permalink" href="#runtests">#</a><code>runtests</code></h3> <pre><code>$harness-&gt;runtests(@tests);</code></pre> <p>Accepts and array of <code>@tests</code> to be run. This should generally be the names of test files, but this is not required. Each element in <code>@tests</code> will be passed to <code>TAP::Parser::new()</code> as a <code>source</code>. See <a href="/5.12.1/TAP::Parser">TAP::Parser</a> for more information.</p> <p>It is possible to provide aliases that will be displayed in place of the test name by supplying the test as a reference to an array containing <code>[ $test, $alias ]</code>:</p> <pre><code>$harness-&gt;runtests( [ &#39;t/foo.t&#39;, &#39;Foo Once&#39; ], [ &#39;t/foo.t&#39;, &#39;Foo Twice&#39; ] );</code></pre> <p>Normally it is an error to attempt to run the same test twice. Aliases allow you to overcome this limitation by giving each run of the test a unique name.</p> <p>Tests will be run in the order found.</p> <p>If the environment variable <code>PERL_TEST_HARNESS_DUMP_TAP</code> is defined it should name a directory into which a copy of the raw TAP for each test will be written. TAP is written to files named for each test. Subdirectories will be created as needed.</p> <p>Returns a <a href="/5.12.1/TAP::Parser::Aggregator">TAP::Parser::Aggregator</a> containing the test results.</p> <h3 id="summary"><a class="permalink" href="#summary">#</a><code>summary</code></h3> <p>Output the summary for a TAP::Parser::Aggregator.</p> <h3 id="aggregate_tests"><a class="permalink" href="#aggregate_tests">#</a><code>aggregate_tests</code></h3> <pre><code>$harness-&gt;aggregate_tests( $aggregate, @tests );</code></pre> <p>Run the named tests and display a summary of result. Tests will be run in the order found.</p> <p>Test results will be added to the supplied <a href="/5.12.1/TAP::Parser::Aggregator">TAP::Parser::Aggregator</a>. <code>aggregate_tests</code> may be called multiple times to run several sets of tests. Multiple <code>Test::Harness</code> instances may be used to pass results to a single aggregator so that different parts of a complex test suite may be run using different <code>TAP::Harness</code> settings. This is useful, for example, in the case where some tests should run in parallel but others are unsuitable for parallel execution.</p> <pre><code>my $formatter = TAP::Formatter::Console-&gt;new; my $ser_harness = TAP::Harness-&gt;new( { formatter =&gt; $formatter } ); my $par_harness = TAP::Harness-&gt;new( { formatter =&gt; $formatter, jobs =&gt; 9 } ); my $aggregator = TAP::Parser::Aggregator-&gt;new; $aggregator-&gt;start(); $ser_harness-&gt;aggregate_tests( $aggregator, @ser_tests ); $par_harness-&gt;aggregate_tests( $aggregator, @par_tests ); $aggregator-&gt;stop(); $formatter-&gt;summary($aggregator);</code></pre> <p>Note that for simpler testing requirements it will often be possible to replace the above code with a single call to <code>runtests</code>.</p> <p>Each elements of the @tests array is either</p> <ul> <li><p>the file name of a test script to run</p> </li> <li><p>a reference to a [ file name, display name ] array</p> </li> </ul> <p>When you supply a separate display name it becomes possible to run a test more than once; the display name is effectively the alias by which the test is known inside the harness. The harness doesn&#39;t care if it runs the same script more than once when each invocation uses a different name.</p> <h3 id="make_scheduler"><a class="permalink" href="#make_scheduler">#</a><code>make_scheduler</code></h3> <p>Called by the harness when it needs to create a <a href="/5.12.1/TAP::Parser::Scheduler">TAP::Parser::Scheduler</a>. Override in a subclass to provide an alternative scheduler. <code>make_scheduler</code> is passed the list of tests that was passed to <code>aggregate_tests</code>.</p> <h3 id="jobs"><a class="permalink" href="#jobs">#</a><code>jobs</code></h3> <p>Gets or sets the number of concurrent test runs the harness is handling. By default, this value is 1 -- for parallel testing, this should be set higher.</p> <h1 id="SUBCLASSING"><a class="permalink" href="#SUBCLASSING">#</a>SUBCLASSING</h1> <p><code>TAP::Harness</code> is designed to be (mostly) easy to subclass. If you don&#39;t like how a particular feature functions, just override the desired methods.</p> <h2 id="Methods"><a class="permalink" href="#Methods">#</a>Methods</h2> <p>TODO: This is out of date</p> <p>The following methods are ones you may wish to override if you want to subclass <code>TAP::Harness</code>.</p> <h3 id="summary1"><a class="permalink" href="#summary1">#</a><code>summary</code></h3> <pre><code>$harness-&gt;summary( \%args );</code></pre> <p><code>summary</code> prints the summary report after all tests are run. The argument is a hashref with the following keys:</p> <ul> <li><p><code>start</code></p> <p>This is created with <code>Benchmark-&gt;new</code> and it the time the tests started. You can print a useful summary time, if desired, with:</p> <pre><code>$self-&gt;output( timestr( timediff( Benchmark-&gt;new, $start_time ), &#39;nop&#39; ) );</code></pre> </li> <li><p><code>tests</code></p> <p>This is an array reference of all test names. To get the <a href="/5.12.1/TAP::Parser">TAP::Parser</a> object for individual tests:</p> <pre><code>my $aggregate = $args-&gt;{aggregate}; my $tests = $args-&gt;{tests}; for my $name ( @$tests ) { my ($parser) = $aggregate-&gt;parsers($test); ... do something with $parser }</code></pre> <p>This is a bit clunky and will be cleaned up in a later release.</p> </li> </ul> <h3 id="make_parser"><a class="permalink" href="#make_parser">#</a><code>make_parser</code></h3> <p>Make a new parser and display formatter session. Typically used and/or overridden in subclasses.</p> <pre><code>my ( $parser, $session ) = $harness-&gt;make_parser;</code></pre> <h3 id="finish_parser"><a class="permalink" href="#finish_parser">#</a><code>finish_parser</code></h3> <p>Terminate use of a parser. Typically used and/or overridden in subclasses. The parser isn&#39;t destroyed as a result of this.</p> <h1 id="REPLACING"><a class="permalink" href="#REPLACING">#</a>REPLACING</h1> <p>If you like the <code>prove</code> utility and <a href="/5.12.1/TAP::Parser">TAP::Parser</a> but you want your own harness, all you need to do is write one and provide <code>new</code> and <code>runtests</code> methods. Then you can use the <code>prove</code> utility like so:</p> <pre><code class="plaintext">prove --harness My::Test::Harness</code></pre> <p>Note that while <code>prove</code> accepts a list of tests (or things to be tested), <code>new</code> has a fairly rich set of arguments. You&#39;ll probably want to read over this code carefully to see how all of them are being used.</p> <h1 id="SEE-ALSO"><a class="permalink" href="#SEE-ALSO">#</a><a id="SEE"></a>SEE ALSO</h1> <p><a href="/5.12.1/Test::Harness">Test::Harness</a></p> </div> <div id="footer"> <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p> <p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p> </div> </div> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script> <script src="/js/highlight.pack.js"></script> <script>hljs.highlightAll();</script> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10