| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "TAP::Harness 3perl" |
| 58 |
.TH TAP::Harness 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide" |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
TAP::Harness \- Run test scripts with statistics |
| 65 |
.SH VERSION |
| 66 |
.IX Header "VERSION" |
| 67 |
Version 3.48 |
| 68 |
.SH DESCRIPTION |
| 69 |
.IX Header "DESCRIPTION" |
| 70 |
This is a simple test harness which allows tests to be run and results |
| 71 |
automatically aggregated and output to STDOUT. |
| 72 |
.SH SYNOPSIS |
| 73 |
.IX Header "SYNOPSIS" |
| 74 |
.Vb 3 |
| 75 |
\& use TAP::Harness; |
| 76 |
\& my $harness = TAP::Harness\->new( \e%args ); |
| 77 |
\& $harness\->runtests(@tests); |
| 78 |
.Ve |
| 79 |
.SH METHODS |
| 80 |
.IX Header "METHODS" |
| 81 |
.SS "Class Methods" |
| 82 |
.IX Subsection "Class Methods" |
| 83 |
\fR\f(CI\*(C`new\*(C'\fR\fI\fR |
| 84 |
.IX Subsection "new" |
| 85 |
.PP |
| 86 |
.Vb 5 |
| 87 |
\& my %args = ( |
| 88 |
\& verbosity => 1, |
| 89 |
\& lib => [ \*(Aqlib\*(Aq, \*(Aqblib/lib\*(Aq, \*(Aqblib/arch\*(Aq ], |
| 90 |
\& ) |
| 91 |
\& my $harness = TAP::Harness\->new( \e%args ); |
| 92 |
.Ve |
| 93 |
.PP |
| 94 |
The constructor returns a new \f(CW\*(C`TAP::Harness\*(C'\fR object. It accepts an |
| 95 |
optional hashref whose allowed keys are: |
| 96 |
.IP \(bu 4 |
| 97 |
\&\f(CW\*(C`verbosity\*(C'\fR |
| 98 |
.Sp |
| 99 |
Set the verbosity level: |
| 100 |
.Sp |
| 101 |
.Vb 6 |
| 102 |
\& 1 verbose Print individual test results to STDOUT. |
| 103 |
\& 0 normal |
| 104 |
\& \-1 quiet Suppress some test output (mostly failures |
| 105 |
\& while tests are running). |
| 106 |
\& \-2 really quiet Suppress everything but the tests summary. |
| 107 |
\& \-3 silent Suppress everything. |
| 108 |
.Ve |
| 109 |
.IP \(bu 4 |
| 110 |
\&\f(CW\*(C`timer\*(C'\fR |
| 111 |
.Sp |
| 112 |
Append run time for each test to output. Uses Time::HiRes if |
| 113 |
available. |
| 114 |
.IP \(bu 4 |
| 115 |
\&\f(CW\*(C`failures\*(C'\fR |
| 116 |
.Sp |
| 117 |
Show test failures (this is a no-op if \f(CW\*(C`verbose\*(C'\fR is selected). |
| 118 |
.IP \(bu 4 |
| 119 |
\&\f(CW\*(C`comments\*(C'\fR |
| 120 |
.Sp |
| 121 |
Show test comments (this is a no-op if \f(CW\*(C`verbose\*(C'\fR is selected). |
| 122 |
.IP \(bu 4 |
| 123 |
\&\f(CW\*(C`show_count\*(C'\fR |
| 124 |
.Sp |
| 125 |
Update the running test count during testing. |
| 126 |
.IP \(bu 4 |
| 127 |
\&\f(CW\*(C`normalize\*(C'\fR |
| 128 |
.Sp |
| 129 |
Set to a true value to normalize the TAP that is emitted in verbose modes. |
| 130 |
.IP \(bu 4 |
| 131 |
\&\f(CW\*(C`lib\*(C'\fR |
| 132 |
.Sp |
| 133 |
Accepts a scalar value or array ref of scalar values indicating which |
| 134 |
paths to allowed libraries should be included if Perl tests are |
| 135 |
executed. Naturally, this only makes sense in the context of tests |
| 136 |
written in Perl. |
| 137 |
.IP \(bu 4 |
| 138 |
\&\f(CW\*(C`switches\*(C'\fR |
| 139 |
.Sp |
| 140 |
Accepts a scalar value or array ref of scalar values indicating which |
| 141 |
switches should be included if Perl tests are executed. Naturally, this |
| 142 |
only makes sense in the context of tests written in Perl. |
| 143 |
.IP \(bu 4 |
| 144 |
\&\f(CW\*(C`test_args\*(C'\fR |
| 145 |
.Sp |
| 146 |
A reference to an \f(CW@INC\fR style array of arguments to be passed to each |
| 147 |
test program. |
| 148 |
.Sp |
| 149 |
.Vb 1 |
| 150 |
\& test_args => [\*(Aqfoo\*(Aq, \*(Aqbar\*(Aq], |
| 151 |
.Ve |
| 152 |
.Sp |
| 153 |
if you want to pass different arguments to each test then you should |
| 154 |
pass a hash of arrays, keyed by the alias for each test: |
| 155 |
.Sp |
| 156 |
.Vb 4 |
| 157 |
\& test_args => { |
| 158 |
\& my_test => [\*(Aqfoo\*(Aq, \*(Aqbar\*(Aq], |
| 159 |
\& other_test => [\*(Aqbaz\*(Aq], |
| 160 |
\& } |
| 161 |
.Ve |
| 162 |
.IP \(bu 4 |
| 163 |
\&\f(CW\*(C`color\*(C'\fR |
| 164 |
.Sp |
| 165 |
Attempt to produce color output. |
| 166 |
.IP \(bu 4 |
| 167 |
\&\f(CW\*(C`exec\*(C'\fR |
| 168 |
.Sp |
| 169 |
Typically, Perl tests are run through this. However, anything which |
| 170 |
spits out TAP is fine. You can use this argument to specify the name of |
| 171 |
the program (and optional switches) to run your tests with: |
| 172 |
.Sp |
| 173 |
.Vb 1 |
| 174 |
\& exec => [\*(Aq/usr/bin/ruby\*(Aq, \*(Aq\-w\*(Aq] |
| 175 |
.Ve |
| 176 |
.Sp |
| 177 |
You can also pass a subroutine reference in order to determine and |
| 178 |
return the proper program to run based on a given test script. The |
| 179 |
subroutine reference should expect the TAP::Harness object itself as the |
| 180 |
first argument, and the file name as the second argument. It should |
| 181 |
return an array reference containing the command to be run and including |
| 182 |
the test file name. It can also simply return \f(CW\*(C`undef\*(C'\fR, in which case |
| 183 |
TAP::Harness will fall back on executing the test script in Perl: |
| 184 |
.Sp |
| 185 |
.Vb 2 |
| 186 |
\& exec => sub { |
| 187 |
\& my ( $harness, $test_file ) = @_; |
| 188 |
\& |
| 189 |
\& # Let Perl tests run. |
| 190 |
\& return undef if $test_file =~ /[.]t$/; |
| 191 |
\& return [ qw( /usr/bin/ruby \-w ), $test_file ] |
| 192 |
\& if $test_file =~ /[.]rb$/; |
| 193 |
\& } |
| 194 |
.Ve |
| 195 |
.Sp |
| 196 |
If the subroutine returns a scalar with a newline or a filehandle, it |
| 197 |
will be interpreted as raw TAP or as a TAP stream, respectively. |
| 198 |
.IP \(bu 4 |
| 199 |
\&\f(CW\*(C`merge\*(C'\fR |
| 200 |
.Sp |
| 201 |
If \f(CW\*(C`merge\*(C'\fR is true the harness will create parsers that merge STDOUT |
| 202 |
and STDERR together for any processes they start. |
| 203 |
.IP \(bu 4 |
| 204 |
\&\f(CW\*(C`sources\*(C'\fR |
| 205 |
.Sp |
| 206 |
\&\fINEW to 3.18\fR. |
| 207 |
.Sp |
| 208 |
If set, \f(CW\*(C`sources\*(C'\fR must be a hashref containing the names of the |
| 209 |
TAP::Parser::SourceHandlers to load and/or configure. The values are a |
| 210 |
hash of configuration that will be accessible to the source handlers via |
| 211 |
"config_for" in TAP::Parser::Source. |
| 212 |
.Sp |
| 213 |
For example: |
| 214 |
.Sp |
| 215 |
.Vb 5 |
| 216 |
\& sources => { |
| 217 |
\& Perl => { exec => \*(Aq/path/to/custom/perl\*(Aq }, |
| 218 |
\& File => { extensions => [ \*(Aq.tap\*(Aq, \*(Aq.txt\*(Aq ] }, |
| 219 |
\& MyCustom => { some => \*(Aqconfig\*(Aq }, |
| 220 |
\& } |
| 221 |
.Ve |
| 222 |
.Sp |
| 223 |
The \f(CW\*(C`sources\*(C'\fR parameter affects how \f(CW\*(C`source\*(C'\fR, \f(CW\*(C`tap\*(C'\fR and \f(CW\*(C`exec\*(C'\fR parameters |
| 224 |
are handled. |
| 225 |
.Sp |
| 226 |
For more details, see the \f(CW\*(C`sources\*(C'\fR parameter in "new" in TAP::Parser, |
| 227 |
TAP::Parser::Source, and TAP::Parser::IteratorFactory. |
| 228 |
.IP \(bu 4 |
| 229 |
\&\f(CW\*(C`aggregator_class\*(C'\fR |
| 230 |
.Sp |
| 231 |
The name of the class to use to aggregate test results. The default is |
| 232 |
TAP::Parser::Aggregator. |
| 233 |
.IP \(bu 4 |
| 234 |
\&\f(CW\*(C`version\*(C'\fR |
| 235 |
.Sp |
| 236 |
\&\fINEW to 3.22\fR. |
| 237 |
.Sp |
| 238 |
Assume this TAP version for TAP::Parser instead of default TAP |
| 239 |
version 12. |
| 240 |
.IP \(bu 4 |
| 241 |
\&\f(CW\*(C`formatter_class\*(C'\fR |
| 242 |
.Sp |
| 243 |
The name of the class to use to format output. The default is |
| 244 |
TAP::Formatter::Console, or TAP::Formatter::File if the output |
| 245 |
isn't a TTY. |
| 246 |
.IP \(bu 4 |
| 247 |
\&\f(CW\*(C`multiplexer_class\*(C'\fR |
| 248 |
.Sp |
| 249 |
The name of the class to use to multiplex tests during parallel testing. |
| 250 |
The default is TAP::Parser::Multiplexer. |
| 251 |
.IP \(bu 4 |
| 252 |
\&\f(CW\*(C`parser_class\*(C'\fR |
| 253 |
.Sp |
| 254 |
The name of the class to use to parse TAP. The default is |
| 255 |
TAP::Parser. |
| 256 |
.IP \(bu 4 |
| 257 |
\&\f(CW\*(C`scheduler_class\*(C'\fR |
| 258 |
.Sp |
| 259 |
The name of the class to use to schedule test execution. The default is |
| 260 |
TAP::Parser::Scheduler. |
| 261 |
.IP \(bu 4 |
| 262 |
\&\f(CW\*(C`formatter\*(C'\fR |
| 263 |
.Sp |
| 264 |
If set \f(CW\*(C`formatter\*(C'\fR must be an object that is capable of formatting the |
| 265 |
TAP output. See TAP::Formatter::Console for an example. |
| 266 |
.IP \(bu 4 |
| 267 |
\&\f(CW\*(C`errors\*(C'\fR |
| 268 |
.Sp |
| 269 |
If parse errors are found in the TAP output, a note of this will be |
| 270 |
made in the summary report. To see all of the parse errors, set this |
| 271 |
argument to true: |
| 272 |
.Sp |
| 273 |
.Vb 1 |
| 274 |
\& errors => 1 |
| 275 |
.Ve |
| 276 |
.IP \(bu 4 |
| 277 |
\&\f(CW\*(C`directives\*(C'\fR |
| 278 |
.Sp |
| 279 |
If set to a true value, only test results with directives will be |
| 280 |
displayed. This overrides other settings such as \f(CW\*(C`verbose\*(C'\fR or |
| 281 |
\&\f(CW\*(C`failures\*(C'\fR. |
| 282 |
.IP \(bu 4 |
| 283 |
\&\f(CW\*(C`ignore_exit\*(C'\fR |
| 284 |
.Sp |
| 285 |
If set to a true value instruct \f(CW\*(C`TAP::Parser\*(C'\fR to ignore exit and wait |
| 286 |
status from test scripts. |
| 287 |
.IP \(bu 4 |
| 288 |
\&\f(CW\*(C`jobs\*(C'\fR |
| 289 |
.Sp |
| 290 |
The maximum number of parallel tests to run at any time. Which tests |
| 291 |
can be run in parallel is controlled by \f(CW\*(C`rules\*(C'\fR. The default is to |
| 292 |
run only one test at a time. |
| 293 |
.IP \(bu 4 |
| 294 |
\&\f(CW\*(C`rules\*(C'\fR |
| 295 |
.Sp |
| 296 |
A reference to a hash of rules that control which tests may be executed in |
| 297 |
parallel. If no rules are declared and CPAN::Meta::YAML is available, |
| 298 |
\&\f(CW\*(C`TAP::Harness\*(C'\fR attempts to load rules from a YAML file specified by the |
| 299 |
\&\f(CW\*(C`rulesfile\*(C'\fR parameter. If no rules file exists, the default is for all |
| 300 |
tests to be eligible to be run in parallel. |
| 301 |
.Sp |
| 302 |
Here some simple examples. For the full details of the data structure |
| 303 |
and the related glob-style pattern matching, see |
| 304 |
"Rules data structure" in TAP::Parser::Scheduler. |
| 305 |
.Sp |
| 306 |
.Vb 4 |
| 307 |
\& # Run all tests in sequence, except those starting with "p" |
| 308 |
\& $harness\->rules({ |
| 309 |
\& par => \*(Aqt/p*.t\*(Aq |
| 310 |
\& }); |
| 311 |
\& |
| 312 |
\& # Equivalent YAML file |
| 313 |
\& \-\-\- |
| 314 |
\& par: t/p*.t |
| 315 |
\& |
| 316 |
\& # Run all tests in parallel, except those starting with "p" |
| 317 |
\& $harness\->rules({ |
| 318 |
\& seq => [ |
| 319 |
\& { seq => \*(Aqt/p*.t\*(Aq }, |
| 320 |
\& { par => \*(Aq**\*(Aq }, |
| 321 |
\& ], |
| 322 |
\& }); |
| 323 |
\& |
| 324 |
\& # Equivalent YAML file |
| 325 |
\& \-\-\- |
| 326 |
\& seq: |
| 327 |
\& \- seq: t/p*.t |
| 328 |
\& \- par: ** |
| 329 |
\& |
| 330 |
\& # Run some startup tests in sequence, then some parallel tests than some |
| 331 |
\& # teardown tests in sequence. |
| 332 |
\& $harness\->rules({ |
| 333 |
\& seq => [ |
| 334 |
\& { seq => \*(Aqt/startup/*.t\*(Aq }, |
| 335 |
\& { par => [\*(Aqt/a/*.t\*(Aq,\*(Aqt/b/*.t\*(Aq,\*(Aqt/c/*.t\*(Aq], } |
| 336 |
\& { seq => \*(Aqt/shutdown/*.t\*(Aq }, |
| 337 |
\& ], |
| 338 |
\& |
| 339 |
\& }); |
| 340 |
\& |
| 341 |
\& # Equivalent YAML file |
| 342 |
\& \-\-\- |
| 343 |
\& seq: |
| 344 |
\& \- seq: t/startup/*.t |
| 345 |
\& \- par: |
| 346 |
\& \- t/a/*.t |
| 347 |
\& \- t/b/*.t |
| 348 |
\& \- t/c/*.t |
| 349 |
\& \- seq: t/shutdown/*.t |
| 350 |
.Ve |
| 351 |
.Sp |
| 352 |
This is an experimental feature and the interface may change. |
| 353 |
.IP \(bu 4 |
| 354 |
\&\f(CW\*(C`rulesfiles\*(C'\fR |
| 355 |
.Sp |
| 356 |
This specifies where to find a YAML file of test scheduling rules. If not |
| 357 |
provided, it looks for a default file to use. It first checks for a file given |
| 358 |
in the \f(CW\*(C`HARNESS_RULESFILE\*(C'\fR environment variable, then it checks for |
| 359 |
\&\fItestrules.yml\fR and then \fIt/testrules.yml\fR. |
| 360 |
.IP \(bu 4 |
| 361 |
\&\f(CW\*(C`stdout\*(C'\fR |
| 362 |
.Sp |
| 363 |
A filehandle for catching standard output. |
| 364 |
.IP \(bu 4 |
| 365 |
\&\f(CW\*(C`trap\*(C'\fR |
| 366 |
.Sp |
| 367 |
Attempt to print summary information if run is interrupted by |
| 368 |
SIGINT (Ctrl-C). |
| 369 |
.PP |
| 370 |
Any keys for which the value is \f(CW\*(C`undef\*(C'\fR will be ignored. |
| 371 |
.SS "Instance Methods" |
| 372 |
.IX Subsection "Instance Methods" |
| 373 |
\fR\f(CI\*(C`runtests\*(C'\fR\fI\fR |
| 374 |
.IX Subsection "runtests" |
| 375 |
.PP |
| 376 |
.Vb 1 |
| 377 |
\& $harness\->runtests(@tests); |
| 378 |
.Ve |
| 379 |
.PP |
| 380 |
Accepts an array of \f(CW@tests\fR to be run. This should generally be the |
| 381 |
names of test files, but this is not required. Each element in \f(CW@tests\fR |
| 382 |
will be passed to \f(CWTAP::Parser::new()\fR as a \f(CW\*(C`source\*(C'\fR. See |
| 383 |
TAP::Parser for more information. |
| 384 |
.PP |
| 385 |
It is possible to provide aliases that will be displayed in place of the |
| 386 |
test name by supplying the test as a reference to an array containing |
| 387 |
\&\f(CW\*(C`[ $test, $alias ]\*(C'\fR: |
| 388 |
.PP |
| 389 |
.Vb 2 |
| 390 |
\& $harness\->runtests( [ \*(Aqt/foo.t\*(Aq, \*(AqFoo Once\*(Aq ], |
| 391 |
\& [ \*(Aqt/foo.t\*(Aq, \*(AqFoo Twice\*(Aq ] ); |
| 392 |
.Ve |
| 393 |
.PP |
| 394 |
Normally it is an error to attempt to run the same test twice. Aliases |
| 395 |
allow you to overcome this limitation by giving each run of the test a |
| 396 |
unique name. |
| 397 |
.PP |
| 398 |
Tests will be run in the order found. |
| 399 |
.PP |
| 400 |
If the environment variable \f(CW\*(C`PERL_TEST_HARNESS_DUMP_TAP\*(C'\fR is defined it |
| 401 |
should name a directory into which a copy of the raw TAP for each test |
| 402 |
will be written. TAP is written to files named for each test. |
| 403 |
Subdirectories will be created as needed. |
| 404 |
.PP |
| 405 |
Returns a TAP::Parser::Aggregator containing the test results. |
| 406 |
.PP |
| 407 |
\fR\f(CI\*(C`summary\*(C'\fR\fI\fR |
| 408 |
.IX Subsection "summary" |
| 409 |
.PP |
| 410 |
.Vb 1 |
| 411 |
\& $harness\->summary( $aggregator ); |
| 412 |
.Ve |
| 413 |
.PP |
| 414 |
Output the summary for a TAP::Parser::Aggregator. |
| 415 |
.PP |
| 416 |
\fR\f(CI\*(C`aggregate_tests\*(C'\fR\fI\fR |
| 417 |
.IX Subsection "aggregate_tests" |
| 418 |
.PP |
| 419 |
.Vb 1 |
| 420 |
\& $harness\->aggregate_tests( $aggregate, @tests ); |
| 421 |
.Ve |
| 422 |
.PP |
| 423 |
Run the named tests and display a summary of result. Tests will be run |
| 424 |
in the order found. |
| 425 |
.PP |
| 426 |
Test results will be added to the supplied TAP::Parser::Aggregator. |
| 427 |
\&\f(CW\*(C`aggregate_tests\*(C'\fR may be called multiple times to run several sets of |
| 428 |
tests. Multiple \f(CW\*(C`Test::Harness\*(C'\fR instances may be used to pass results |
| 429 |
to a single aggregator so that different parts of a complex test suite |
| 430 |
may be run using different \f(CW\*(C`TAP::Harness\*(C'\fR settings. This is useful, for |
| 431 |
example, in the case where some tests should run in parallel but others |
| 432 |
are unsuitable for parallel execution. |
| 433 |
.PP |
| 434 |
.Vb 8 |
| 435 |
\& my $formatter = TAP::Formatter::Console\->new; |
| 436 |
\& my $ser_harness = TAP::Harness\->new( { formatter => $formatter } ); |
| 437 |
\& my $par_harness = TAP::Harness\->new( |
| 438 |
\& { formatter => $formatter, |
| 439 |
\& jobs => 9 |
| 440 |
\& } |
| 441 |
\& ); |
| 442 |
\& my $aggregator = TAP::Parser::Aggregator\->new; |
| 443 |
\& |
| 444 |
\& $aggregator\->start(); |
| 445 |
\& $ser_harness\->aggregate_tests( $aggregator, @ser_tests ); |
| 446 |
\& $par_harness\->aggregate_tests( $aggregator, @par_tests ); |
| 447 |
\& $aggregator\->stop(); |
| 448 |
\& $formatter\->summary($aggregator); |
| 449 |
.Ve |
| 450 |
.PP |
| 451 |
Note that for simpler testing requirements it will often be possible to |
| 452 |
replace the above code with a single call to \f(CW\*(C`runtests\*(C'\fR. |
| 453 |
.PP |
| 454 |
Each element of the \f(CW@tests\fR array is either: |
| 455 |
.IP \(bu 4 |
| 456 |
the source name of a test to run |
| 457 |
.IP \(bu 4 |
| 458 |
a reference to a [ source name, display name ] array |
| 459 |
.PP |
| 460 |
In the case of a perl test suite, typically \fIsource names\fR are simply the file |
| 461 |
names of the test scripts to run. |
| 462 |
.PP |
| 463 |
When you supply a separate display name it becomes possible to run a |
| 464 |
test more than once; the display name is effectively the alias by which |
| 465 |
the test is known inside the harness. The harness doesn't care if it |
| 466 |
runs the same test more than once when each invocation uses a |
| 467 |
different name. |
| 468 |
.PP |
| 469 |
\fR\f(CI\*(C`make_scheduler\*(C'\fR\fI\fR |
| 470 |
.IX Subsection "make_scheduler" |
| 471 |
.PP |
| 472 |
Called by the harness when it needs to create a |
| 473 |
TAP::Parser::Scheduler. Override in a subclass to provide an |
| 474 |
alternative scheduler. \f(CW\*(C`make_scheduler\*(C'\fR is passed the list of tests |
| 475 |
that was passed to \f(CW\*(C`aggregate_tests\*(C'\fR. |
| 476 |
.PP |
| 477 |
\fR\f(CI\*(C`jobs\*(C'\fR\fI\fR |
| 478 |
.IX Subsection "jobs" |
| 479 |
.PP |
| 480 |
Gets or sets the number of concurrent test runs the harness is |
| 481 |
handling. By default, this value is 1 \-\- for parallel testing, this |
| 482 |
should be set higher. |
| 483 |
.PP |
| 484 |
\fR\f(CI\*(C`make_parser\*(C'\fR\fI\fR |
| 485 |
.IX Subsection "make_parser" |
| 486 |
.PP |
| 487 |
Make a new parser and display formatter session. Typically used and/or |
| 488 |
overridden in subclasses. |
| 489 |
.PP |
| 490 |
.Vb 1 |
| 491 |
\& my ( $parser, $session ) = $harness\->make_parser; |
| 492 |
.Ve |
| 493 |
.PP |
| 494 |
\fR\f(CI\*(C`finish_parser\*(C'\fR\fI\fR |
| 495 |
.IX Subsection "finish_parser" |
| 496 |
.PP |
| 497 |
Terminate use of a parser. Typically used and/or overridden in |
| 498 |
subclasses. The parser isn't destroyed as a result of this. |
| 499 |
.SH CONFIGURING |
| 500 |
.IX Header "CONFIGURING" |
| 501 |
\&\f(CW\*(C`TAP::Harness\*(C'\fR is designed to be easy to configure. |
| 502 |
.SS Plugins |
| 503 |
.IX Subsection "Plugins" |
| 504 |
\&\f(CW\*(C`TAP::Parser\*(C'\fR plugins let you change the way TAP is \fIinput\fR to and \fIoutput\fR |
| 505 |
from the parser. |
| 506 |
.PP |
| 507 |
TAP::Parser::SourceHandlers handle TAP \fIinput\fR. You can configure them |
| 508 |
and load custom handlers using the \f(CW\*(C`sources\*(C'\fR parameter to "new". |
| 509 |
.PP |
| 510 |
TAP::Formatters handle TAP \fIoutput\fR. You can load custom formatters by |
| 511 |
using the \f(CW\*(C`formatter_class\*(C'\fR parameter to "new". To configure a formatter, |
| 512 |
you currently need to instantiate it outside of TAP::Harness and pass it in |
| 513 |
with the \f(CW\*(C`formatter\*(C'\fR parameter to "new". This \fImay\fR be addressed by adding |
| 514 |
a \fIformatters\fR parameter to "new" in the future. |
| 515 |
.ie n .SS """Module::Build""" |
| 516 |
.el .SS \f(CWModule::Build\fP |
| 517 |
.IX Subsection "Module::Build" |
| 518 |
Module::Build version \f(CW0.30\fR supports \f(CW\*(C`TAP::Harness\*(C'\fR. |
| 519 |
.PP |
| 520 |
To load \f(CW\*(C`TAP::Harness\*(C'\fR plugins, you'll need to use the \f(CW\*(C`tap_harness_args\*(C'\fR |
| 521 |
parameter to \f(CW\*(C`new\*(C'\fR, typically from your \f(CW\*(C`Build.PL\*(C'\fR. For example: |
| 522 |
.PP |
| 523 |
.Vb 10 |
| 524 |
\& Module::Build\->new( |
| 525 |
\& module_name => \*(AqMyApp\*(Aq, |
| 526 |
\& test_file_exts => [qw(.t .tap .txt)], |
| 527 |
\& use_tap_harness => 1, |
| 528 |
\& tap_harness_args => { |
| 529 |
\& sources => { |
| 530 |
\& MyCustom => {}, |
| 531 |
\& File => { |
| 532 |
\& extensions => [\*(Aq.tap\*(Aq, \*(Aq.txt\*(Aq], |
| 533 |
\& }, |
| 534 |
\& }, |
| 535 |
\& formatter_class => \*(AqTAP::Formatter::HTML\*(Aq, |
| 536 |
\& }, |
| 537 |
\& build_requires => { |
| 538 |
\& \*(AqModule::Build\*(Aq => \*(Aq0.30\*(Aq, |
| 539 |
\& \*(AqTAP::Harness\*(Aq => \*(Aq3.18\*(Aq, |
| 540 |
\& }, |
| 541 |
\& )\->create_build_script; |
| 542 |
.Ve |
| 543 |
.PP |
| 544 |
See "new" |
| 545 |
.ie n .SS """ExtUtils::MakeMaker""" |
| 546 |
.el .SS \f(CWExtUtils::MakeMaker\fP |
| 547 |
.IX Subsection "ExtUtils::MakeMaker" |
| 548 |
ExtUtils::MakeMaker does not support TAP::Harness out-of-the-box. |
| 549 |
.ie n .SS """prove""" |
| 550 |
.el .SS \f(CWprove\fP |
| 551 |
.IX Subsection "prove" |
| 552 |
prove supports \f(CW\*(C`TAP::Harness\*(C'\fR plugins, and has a plugin system of its |
| 553 |
own. See "FORMATTERS" in prove, "SOURCE HANDLERS" in prove and App::Prove |
| 554 |
for more details. |
| 555 |
.SH "WRITING PLUGINS" |
| 556 |
.IX Header "WRITING PLUGINS" |
| 557 |
If you can't configure \f(CW\*(C`TAP::Harness\*(C'\fR to do what you want, and you can't find |
| 558 |
an existing plugin, consider writing one. |
| 559 |
.PP |
| 560 |
The two primary use cases supported by TAP::Harness for plugins are \fIinput\fR |
| 561 |
and \fIoutput\fR: |
| 562 |
.IP "Customize how TAP gets into the parser" 2 |
| 563 |
.IX Item "Customize how TAP gets into the parser" |
| 564 |
To do this, you can either extend an existing TAP::Parser::SourceHandler, |
| 565 |
or write your own. It's a pretty simple API, and they can be loaded and |
| 566 |
configured using the \f(CW\*(C`sources\*(C'\fR parameter to "new". |
| 567 |
.IP "Customize how TAP results are output from the parser" 2 |
| 568 |
.IX Item "Customize how TAP results are output from the parser" |
| 569 |
To do this, you can either extend an existing TAP::Formatter, or write your |
| 570 |
own. Writing formatters are a bit more involved than writing a |
| 571 |
\&\fISourceHandler\fR, as you'll need to understand the TAP::Parser API. A |
| 572 |
good place to start is by understanding how "aggregate_tests" works. |
| 573 |
.Sp |
| 574 |
Custom formatters can be loaded configured using the \f(CW\*(C`formatter_class\*(C'\fR |
| 575 |
parameter to "new". |
| 576 |
.SH SUBCLASSING |
| 577 |
.IX Header "SUBCLASSING" |
| 578 |
If you can't configure \f(CW\*(C`TAP::Harness\*(C'\fR to do exactly what you want, and writing |
| 579 |
a plugin isn't an option, consider extending it. It is designed to be (mostly) |
| 580 |
easy to subclass, though the cases when sub-classing is necessary should be few |
| 581 |
and far between. |
| 582 |
.SS Methods |
| 583 |
.IX Subsection "Methods" |
| 584 |
The following methods are ones you may wish to override if you want to |
| 585 |
subclass \f(CW\*(C`TAP::Harness\*(C'\fR. |
| 586 |
.IP """new""" 4 |
| 587 |
.IX Item """new""" |
| 588 |
.PD 0 |
| 589 |
.IP """runtests""" 4 |
| 590 |
.IX Item """runtests""" |
| 591 |
.IP """summary""" 4 |
| 592 |
.IX Item """summary""" |
| 593 |
.PD |
| 594 |
.SH REPLACING |
| 595 |
.IX Header "REPLACING" |
| 596 |
If you like the \f(CW\*(C`prove\*(C'\fR utility and TAP::Parser but you want your |
| 597 |
own harness, all you need to do is write one and provide \f(CW\*(C`new\*(C'\fR and |
| 598 |
\&\f(CW\*(C`runtests\*(C'\fR methods. Then you can use the \f(CW\*(C`prove\*(C'\fR utility like so: |
| 599 |
.PP |
| 600 |
.Vb 1 |
| 601 |
\& prove \-\-harness My::Test::Harness |
| 602 |
.Ve |
| 603 |
.PP |
| 604 |
Note that while \f(CW\*(C`prove\*(C'\fR accepts a list of tests (or things to be |
| 605 |
tested), \f(CW\*(C`new\*(C'\fR has a fairly rich set of arguments. You'll probably want |
| 606 |
to read over this code carefully to see how all of them are being used. |
| 607 |
.SH "SEE ALSO" |
| 608 |
.IX Header "SEE ALSO" |
| 609 |
Test::Harness |