{
    "content": [
        {
            "type": "text",
            "text": "# TAP::Harness (perldoc)\n\n## NAME\n\nTAP::Harness - Run test scripts with statistics\n\n## SYNOPSIS\n\nuse TAP::Harness;\nmy $harness = TAP::Harness->new( \\%args );\n$harness->runtests(@tests);\n\n## DESCRIPTION\n\nThis is a simple test harness which allows tests to be run and results automatically aggregated\nand output to STDOUT.\n\n## Sections\n\n- **NAME**\n- **VERSION**\n- **DESCRIPTION**\n- **SYNOPSIS**\n- **METHODS** (2 subsections)\n- **CONFIGURING** (1 subsections)\n- **WRITING PLUGINS**\n- **SUBCLASSING** (1 subsections)\n- **REPLACING**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "TAP::Harness",
        "section": "",
        "mode": "perldoc",
        "summary": "TAP::Harness - Run test scripts with statistics",
        "synopsis": "use TAP::Harness;\nmy $harness = TAP::Harness->new( \\%args );\n$harness->runtests(@tests);",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "VERSION",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "METHODS",
                "lines": 1,
                "subsections": [
                    {
                        "name": "Class Methods",
                        "lines": 253
                    },
                    {
                        "name": "Instance Methods",
                        "lines": 89
                    }
                ]
            },
            {
                "name": "CONFIGURING",
                "lines": 2,
                "subsections": [
                    {
                        "name": "Plugins",
                        "lines": 44
                    }
                ]
            },
            {
                "name": "WRITING PLUGINS",
                "lines": 18,
                "subsections": []
            },
            {
                "name": "SUBCLASSING",
                "lines": 4,
                "subsections": [
                    {
                        "name": "Methods",
                        "lines": 6
                    }
                ]
            },
            {
                "name": "REPLACING",
                "lines": 10,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "TAP::Harness - Run test scripts with statistics\n",
                "subsections": []
            },
            "VERSION": {
                "content": "Version 3.43\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "This is a simple test harness which allows tests to be run and results automatically aggregated\nand output to STDOUT.\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use TAP::Harness;\nmy $harness = TAP::Harness->new( \\%args );\n$harness->runtests(@tests);\n",
                "subsections": []
            },
            "METHODS": {
                "content": "",
                "subsections": [
                    {
                        "name": "Class Methods",
                        "content": "\"new\"\nmy %args = (\nverbosity => 1,\nlib     => [ 'lib', 'blib/lib', 'blib/arch' ],\n)\nmy $harness = TAP::Harness->new( \\%args );\n\nThe constructor returns a new \"TAP::Harness\" object. It accepts an optional hashref whose\nallowed keys are:\n\n*   \"verbosity\"\n\nSet the verbosity level:\n\n1   verbose        Print individual test results to STDOUT.\n0   normal\n-1   quiet          Suppress some test output (mostly failures\nwhile tests are running).\n-2   really quiet   Suppress everything but the tests summary.\n-3   silent         Suppress everything.\n\n*   \"timer\"\n\nAppend run time for each test to output. Uses Time::HiRes if available.\n\n*   \"failures\"\n\nShow test failures (this is a no-op if \"verbose\" is selected).\n\n*   \"comments\"\n\nShow test comments (this is a no-op if \"verbose\" is selected).\n\n*   \"showcount\"\n\nUpdate the running test count during testing.\n\n*   \"normalize\"\n\nSet to a true value to normalize the TAP that is emitted in verbose modes.\n\n*   \"lib\"\n\nAccepts a scalar value or array ref of scalar values indicating which paths to allowed\nlibraries should be included if Perl tests are executed. Naturally, this only makes sense in\nthe context of tests written in Perl.\n\n*   \"switches\"\n\nAccepts a scalar value or array ref of scalar values indicating which switches should be\nincluded if Perl tests are executed. Naturally, this only makes sense in the context of\ntests written in Perl.\n\n*   \"testargs\"\n\nA reference to an @INC style array of arguments to be passed to each test program.\n\ntestargs => ['foo', 'bar'],\n\nif you want to pass different arguments to each test then you should pass a hash of arrays,\nkeyed by the alias for each test:\n\ntestargs => {\nmytest    => ['foo', 'bar'],\nothertest => ['baz'],\n}\n\n*   \"color\"\n\nAttempt to produce color output.\n\n*   \"exec\"\n\nTypically, Perl tests are run through this. However, anything which spits out TAP is fine.\nYou can use this argument to specify the name of the program (and optional switches) to run\nyour tests with:\n\nexec => ['/usr/bin/ruby', '-w']\n\nYou can also pass a subroutine reference in order to determine and return the proper program\nto run based on a given test script. The subroutine reference should expect the TAP::Harness\nobject itself as the first argument, and the file name as the second argument. It should\nreturn an array reference containing the command to be run and including the test file name.\nIt can also simply return \"undef\", in which case TAP::Harness will fall back on executing\nthe test script in Perl:\n\nexec => sub {\nmy ( $harness, $testfile ) = @;\n\n# Let Perl tests run.\nreturn undef if $testfile =~ /[.]t$/;\nreturn [ qw( /usr/bin/ruby -w ), $testfile ]\nif $testfile =~ /[.]rb$/;\n}\n\nIf the subroutine returns a scalar with a newline or a filehandle, it will be interpreted as\nraw TAP or as a TAP stream, respectively.\n\n*   \"merge\"\n\nIf \"merge\" is true the harness will create parsers that merge STDOUT and STDERR together for\nany processes they start.\n\n*   \"sources\"\n\n*NEW to 3.18*.\n\nIf set, \"sources\" must be a hashref containing the names of the TAP::Parser::SourceHandlers\nto load and/or configure. The values are a hash of configuration that will be accessible to\nthe source handlers via \"configfor\" in TAP::Parser::Source.\n\nFor example:\n\nsources => {\nPerl => { exec => '/path/to/custom/perl' },\nFile => { extensions => [ '.tap', '.txt' ] },\nMyCustom => { some => 'config' },\n}\n\nThe \"sources\" parameter affects how \"source\", \"tap\" and \"exec\" parameters are handled.\n\nFor more details, see the \"sources\" parameter in \"new\" in TAP::Parser, TAP::Parser::Source,\nand TAP::Parser::IteratorFactory.\n\n*   \"aggregatorclass\"\n\nThe name of the class to use to aggregate test results. The default is\nTAP::Parser::Aggregator.\n\n*   \"version\"\n\n*NEW to 3.22*.\n\nAssume this TAP version for TAP::Parser instead of default TAP version 12.\n\n*   \"formatterclass\"\n\nThe name of the class to use to format output. The default is TAP::Formatter::Console, or\nTAP::Formatter::File if the output isn't a TTY.\n\n*   \"multiplexerclass\"\n\nThe name of the class to use to multiplex tests during parallel testing. The default is\nTAP::Parser::Multiplexer.\n\n*   \"parserclass\"\n\nThe name of the class to use to parse TAP. The default is TAP::Parser.\n\n*   \"schedulerclass\"\n\nThe name of the class to use to schedule test execution. The default is\nTAP::Parser::Scheduler.\n\n*   \"formatter\"\n\nIf set \"formatter\" must be an object that is capable of formatting the TAP output. See\nTAP::Formatter::Console for an example.\n\n*   \"errors\"\n\nIf parse errors are found in the TAP output, a note of this will be made in the summary\nreport. To see all of the parse errors, set this argument to true:\n\nerrors => 1\n\n*   \"directives\"\n\nIf set to a true value, only test results with directives will be displayed. This overrides\nother settings such as \"verbose\" or \"failures\".\n\n*   \"ignoreexit\"\n\nIf set to a true value instruct \"TAP::Parser\" to ignore exit and wait status from test\nscripts.\n\n*   \"jobs\"\n\nThe maximum number of parallel tests to run at any time. Which tests can be run in parallel\nis controlled by \"rules\". The default is to run only one test at a time.\n\n*   \"rules\"\n\nA reference to a hash of rules that control which tests may be executed in parallel. If no\nrules are declared and CPAN::Meta::YAML is available, \"TAP::Harness\" attempts to load rules\nfrom a YAML file specified by the \"rulesfile\" parameter. If no rules file exists, the\ndefault is for all tests to be eligible to be run in parallel.\n\nHere some simple examples. For the full details of the data structure and the related\nglob-style pattern matching, see \"Rules data structure\" in TAP::Parser::Scheduler.\n\n# Run all tests in sequence, except those starting with \"p\"\n$harness->rules({\npar => 't/p*.t'\n});\n\n# Equivalent YAML file\n---\npar: t/p*.t\n\n# Run all tests in parallel, except those starting with \"p\"\n$harness->rules({\nseq => [\n{ seq => 't/p*.t' },\n{ par => ''     },\n],\n});\n\n# Equivalent YAML file\n---\nseq:\n- seq: t/p*.t\n- par:\n\n# Run some  startup tests in sequence, then some parallel tests than some\n# teardown tests in sequence.\n$harness->rules({\nseq => [\n{ seq => 't/startup/*.t' },\n{ par => ['t/a/*.t','t/b/*.t','t/c/*.t'], }\n{ seq => 't/shutdown/*.t' },\n],\n\n});\n\n# Equivalent YAML file\n---\nseq:\n- seq: t/startup/*.t\n- par:\n- t/a/*.t\n- t/b/*.t\n- t/c/*.t\n- seq: t/shutdown/*.t\n\nThis is an experimental feature and the interface may change.\n\n*   \"rulesfiles\"\n\nThis specifies where to find a YAML file of test scheduling rules. If not provided, it looks\nfor a default file to use. It first checks for a file given in the \"HARNESSRULESFILE\"\nenvironment variable, then it checks for testrules.yml and then t/testrules.yml.\n\n*   \"stdout\"\n\nA filehandle for catching standard output.\n\n*   \"trap\"\n\nAttempt to print summary information if run is interrupted by SIGINT (Ctrl-C).\n\nAny keys for which the value is \"undef\" will be ignored.\n"
                    },
                    {
                        "name": "Instance Methods",
                        "content": "\"runtests\"\n$harness->runtests(@tests);\n\nAccepts an array of @tests to be run. This should generally be the names of test files, but this\nis not required. Each element in @tests will be passed to \"TAP::Parser::new()\" as a \"source\".\nSee TAP::Parser for more information.\n\nIt is possible to provide aliases that will be displayed in place of the test name by supplying\nthe test as a reference to an array containing \"[ $test, $alias ]\":\n\n$harness->runtests( [ 't/foo.t', 'Foo Once' ],\n[ 't/foo.t', 'Foo Twice' ] );\n\nNormally it is an error to attempt to run the same test twice. Aliases allow you to overcome\nthis limitation by giving each run of the test a unique name.\n\nTests will be run in the order found.\n\nIf the environment variable \"PERLTESTHARNESSDUMPTAP\" is defined it should name a directory\ninto which a copy of the raw TAP for each test will be written. TAP is written to files named\nfor each test. Subdirectories will be created as needed.\n\nReturns a TAP::Parser::Aggregator containing the test results.\n\n\"summary\"\n$harness->summary( $aggregator );\n\nOutput the summary for a TAP::Parser::Aggregator.\n\n\"aggregatetests\"\n$harness->aggregatetests( $aggregate, @tests );\n\nRun the named tests and display a summary of result. Tests will be run in the order found.\n\nTest results will be added to the supplied TAP::Parser::Aggregator. \"aggregatetests\" may be\ncalled multiple times to run several sets of tests. Multiple \"Test::Harness\" instances may be\nused to pass results to a single aggregator so that different parts of a complex test suite may\nbe run using different \"TAP::Harness\" settings. This is useful, for example, in the case where\nsome tests should run in parallel but others are unsuitable for parallel execution.\n\nmy $formatter   = TAP::Formatter::Console->new;\nmy $serharness = TAP::Harness->new( { formatter => $formatter } );\nmy $parharness = TAP::Harness->new(\n{   formatter => $formatter,\njobs      => 9\n}\n);\nmy $aggregator = TAP::Parser::Aggregator->new;\n\n$aggregator->start();\n$serharness->aggregatetests( $aggregator, @sertests );\n$parharness->aggregatetests( $aggregator, @partests );\n$aggregator->stop();\n$formatter->summary($aggregator);\n\nNote that for simpler testing requirements it will often be possible to replace the above code\nwith a single call to \"runtests\".\n\nEach element of the @tests array is either:\n\n*   the source name of a test to run\n\n*   a reference to a [ source name, display name ] array\n\nIn the case of a perl test suite, typically *source names* are simply the file names of the test\nscripts to run.\n\nWhen you supply a separate display name it becomes possible to run a test more than once; the\ndisplay name is effectively the alias by which the test is known inside the harness. The harness\ndoesn't care if it runs the same test more than once when each invocation uses a different name.\n\n\"makescheduler\"\nCalled by the harness when it needs to create a TAP::Parser::Scheduler. Override in a subclass\nto provide an alternative scheduler. \"makescheduler\" is passed the list of tests that was\npassed to \"aggregatetests\".\n\n\"jobs\"\nGets or sets the number of concurrent test runs the harness is handling. By default, this value\nis 1 -- for parallel testing, this should be set higher.\n\n\"makeparser\"\nMake a new parser and display formatter session. Typically used and/or overridden in subclasses.\n\nmy ( $parser, $session ) = $harness->makeparser;\n\n\"finishparser\"\nTerminate use of a parser. Typically used and/or overridden in subclasses. The parser isn't\ndestroyed as a result of this.\n"
                    }
                ]
            },
            "CONFIGURING": {
                "content": "\"TAP::Harness\" is designed to be easy to configure.\n",
                "subsections": [
                    {
                        "name": "Plugins",
                        "content": "\"TAP::Parser\" plugins let you change the way TAP is *input* to and *output* from the parser.\n\nTAP::Parser::SourceHandlers handle TAP *input*. You can configure them and load custom handlers\nusing the \"sources\" parameter to \"new\".\n\nTAP::Formatters handle TAP *output*. You can load custom formatters by using the\n\"formatterclass\" parameter to \"new\". To configure a formatter, you currently need to\ninstantiate it outside of TAP::Harness and pass it in with the \"formatter\" parameter to \"new\".\nThis *may* be addressed by adding a *formatters* parameter to \"new\" in the future.\n\n\"Module::Build\"\nModule::Build version 0.30 supports \"TAP::Harness\".\n\nTo load \"TAP::Harness\" plugins, you'll need to use the \"tapharnessargs\" parameter to \"new\",\ntypically from your \"Build.PL\". For example:\n\nModule::Build->new(\nmodulename        => 'MyApp',\ntestfileexts     => [qw(.t .tap .txt)],\nusetapharness    => 1,\ntapharnessargs   => {\nsources => {\nMyCustom => {},\nFile => {\nextensions => ['.tap', '.txt'],\n},\n},\nformatterclass => 'TAP::Formatter::HTML',\n},\nbuildrequires     => {\n'Module::Build' => '0.30',\n'TAP::Harness'  => '3.18',\n},\n)->createbuildscript;\n\nSee \"new\"\n\n\"ExtUtils::MakeMaker\"\nExtUtils::MakeMaker does not support TAP::Harness out-of-the-box.\n\n\"prove\"\nprove supports \"TAP::Harness\" plugins, and has a plugin system of its own. See \"FORMATTERS\" in\nprove, \"SOURCE HANDLERS\" in prove and App::Prove for more details.\n"
                    }
                ]
            },
            "WRITING PLUGINS": {
                "content": "If you can't configure \"TAP::Harness\" to do what you want, and you can't find an existing\nplugin, consider writing one.\n\nThe two primary use cases supported by TAP::Harness for plugins are *input* and *output*:\n\nCustomize how TAP gets into the parser\nTo do this, you can either extend an existing TAP::Parser::SourceHandler, or write your own.\nIt's a pretty simple API, and they can be loaded and configured using the \"sources\" parameter\nto \"new\".\n\nCustomize how TAP results are output from the parser\nTo do this, you can either extend an existing TAP::Formatter, or write your own. Writing\nformatters are a bit more involved than writing a *SourceHandler*, as you'll need to\nunderstand the TAP::Parser API. A good place to start is by understanding how\n\"aggregatetests\" works.\n\nCustom formatters can be loaded configured using the \"formatterclass\" parameter to \"new\".\n",
                "subsections": []
            },
            "SUBCLASSING": {
                "content": "If you can't configure \"TAP::Harness\" to do exactly what you want, and writing a plugin isn't an\noption, consider extending it. It is designed to be (mostly) easy to subclass, though the cases\nwhen sub-classing is necessary should be few and far between.\n",
                "subsections": [
                    {
                        "name": "Methods",
                        "content": "The following methods are ones you may wish to override if you want to subclass \"TAP::Harness\".\n\n\"new\"\n\"runtests\"\n\"summary\"\n"
                    }
                ]
            },
            "REPLACING": {
                "content": "If you like the \"prove\" utility and TAP::Parser but you want your own harness, all you need to\ndo is write one and provide \"new\" and \"runtests\" methods. Then you can use the \"prove\" utility\nlike so:\n\nprove --harness My::Test::Harness\n\nNote that while \"prove\" accepts a list of tests (or things to be tested), \"new\" has a fairly\nrich set of arguments. You'll probably want to read over this code carefully to see how all of\nthem are being used.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "Test::Harness\n",
                "subsections": []
            }
        }
    }
}