{
    "content": [
        {
            "type": "text",
            "text": "# Test::Builder (info)\n\n## NAME\n\nTest::Builder - Backend for building test libraries\n\n## SYNOPSIS\n\npackage My::Test::Module;\nuse base 'Test::Builder::Module';\nmy $CLASS = PACKAGE;\nsub ok {\nmy($test, $name) = @;\nmy $tb = $CLASS->builder;\n$tb->ok($test, $name);\n}\n\n## DESCRIPTION\n\nTest::Simple and Test::More have proven to be popular testing modules,\nbut they're not always flexible enough.  Test::Builder provides a\nbuilding block upon which to write your own test libraries which can\nwork together.\n\n## Sections\n\n- **Test::Builder(3perl)   Perl Programmers Reference Guide   Test::Builder(3perl)**\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **EXIT CODES**\n- **THREADS**\n- **MEMORY**\n- **EXAMPLES**\n- **SEE ALSO**\n- **AUTHORS**\n- **MAINTAINERS**\n- **COPYRIGHT**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Test::Builder",
        "section": "",
        "mode": "info",
        "summary": "Test::Builder - Backend for building test libraries",
        "synopsis": "package My::Test::Module;\nuse base 'Test::Builder::Module';\nmy $CLASS = PACKAGE;\nsub ok {\nmy($test, $name) = @;\nmy $tb = $CLASS->builder;\n$tb->ok($test, $name);\n}",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [
            "CPAN can provide the best examples.  Test::Simple, Test::More,",
            "Test::Exception and Test::Differences all use Test::Builder."
        ],
        "see_also": [],
        "section_outline": [
            {
                "name": "Test::Builder(3perl)   Perl Programmers Reference Guide   Test::Builder(3perl)",
                "lines": 1,
                "subsections": []
            },
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 12,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 607,
                "subsections": []
            },
            {
                "name": "EXIT CODES",
                "lines": 16,
                "subsections": []
            },
            {
                "name": "THREADS",
                "lines": 22,
                "subsections": []
            },
            {
                "name": "MEMORY",
                "lines": 12,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 9,
                "subsections": []
            },
            {
                "name": "AUTHORS",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "MAINTAINERS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "COPYRIGHT",
                "lines": 9,
                "subsections": []
            }
        ],
        "sections": {
            "Test::Builder(3perl)   Perl Programmers Reference Guide   Test::Builder(3perl)": {
                "content": "",
                "subsections": []
            },
            "NAME": {
                "content": "Test::Builder - Backend for building test libraries\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "package My::Test::Module;\nuse base 'Test::Builder::Module';\n\nmy $CLASS = PACKAGE;\n\nsub ok {\nmy($test, $name) = @;\nmy $tb = $CLASS->builder;\n\n$tb->ok($test, $name);\n}\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "Test::Simple and Test::More have proven to be popular testing modules,\nbut they're not always flexible enough.  Test::Builder provides a\nbuilding block upon which to write your own test libraries which can\nwork together.\n\nConstruction\nnew\nmy $Test = Test::Builder->new;\n\nReturns a Test::Builder object representing the current state of\nthe test.\n\nSince you only run one test per program \"new\" always returns the\nsame Test::Builder object.  No matter how many times you call\n\"new()\", you're getting the same object.  This is called a\nsingleton.  This is done so that multiple modules share such global\ninformation as the test counter and where test output is going.\n\nIf you want a completely new Test::Builder object different from\nthe singleton, use \"create\".\n\ncreate\nmy $Test = Test::Builder->create;\n\nOk, so there can be more than one Test::Builder object and this is\nhow you get it.  You might use this instead of \"new()\" if you're\ntesting a Test::Builder based module, but otherwise you probably\nwant \"new\".\n\nNOTE: the implementation is not complete.  \"level\", for example, is\nstill shared by all Test::Builder objects, even ones created using\nthis method.  Also, the method name may change in the future.\n\nsubtest\n$builder->subtest($name, \\&subtests, @args);\n\nSee documentation of \"subtest\" in Test::More.\n\n\"subtest\" also, and optionally, accepts arguments which will be\npassed to the subtests reference.\n\nname\ndiag $builder->name;\n\nReturns the name of the current builder.  Top level builders\ndefault to $0 (the name of the executable).  Child builders are\nnamed via the \"child\" method.  If no name is supplied, will be\nnamed \"Child of $parent->name\".\n\nreset\n$Test->reset;\n\nReinitializes the Test::Builder singleton to its original state.\nMostly useful for tests run in persistent environments where the\nsame test might be run multiple times in the same process.\n\nSetting up tests\nThese methods are for setting up tests and declaring how many there\nare.  You usually only want to call one of these methods.\n\nplan\n$Test->plan('noplan');\n$Test->plan( skipall => $reason );\n$Test->plan( tests => $numtests );\n\nA convenient way to set up your tests.  Call this and Test::Builder\nwill print the appropriate headers and take the appropriate\nactions.\n\nIf you call \"plan()\", don't call any of the other methods below.\n\nexpectedtests\nmy $max = $Test->expectedtests;\n$Test->expectedtests($max);\n\nGets/sets the number of tests we expect this test to run and prints\nout the appropriate headers.\n\nnoplan\n$Test->noplan;\n\nDeclares that this test will run an indeterminate number of tests.\n\ndonetesting\n$Test->donetesting();\n$Test->donetesting($numtests);\n\nDeclares that you are done testing, no more tests will be run after\nthis point.\n\nIf a plan has not yet been output, it will do so.\n\n$numtests is the number of tests you planned to run.  If a\nnumbered plan was already declared, and if this contradicts, a\nfailing test will be run to reflect the planning mistake.  If\n\"noplan\" was declared, this will override.\n\nIf \"donetesting()\" is called twice, the second call will issue a\nfailing test.\n\nIf $numtests is omitted, the number of tests run will be used,\nlike noplan.\n\n\"donetesting()\" is, in effect, used when you'd want to use\n\"noplan\", but safer. You'd use it like so:\n\n$Test->ok($a == $b);\n$Test->donetesting();\n\nOr to plan a variable number of tests:\n\nfor my $test (@tests) {\n$Test->ok($test);\n}\n$Test->donetesting(scalar @tests);\n\nhasplan\n$plan = $Test->hasplan\n\nFind out whether a plan has been defined. $plan is either \"undef\"\n(no plan has been set), \"noplan\" (indeterminate # of tests) or an\ninteger (the number of expected tests).\n\nskipall\n$Test->skipall;\n$Test->skipall($reason);\n\nSkips all the tests, using the given $reason.  Exits immediately\nwith 0.\n\nexportedto\nmy $pack = $Test->exportedto;\n$Test->exportedto($pack);\n\nTells Test::Builder what package you exported your functions to.\n\nThis method isn't terribly useful since modules which share the\nsame Test::Builder object might get exported to different packages\nand only the last one will be honored.\n\nRunning tests\nThese actually run the tests, analogous to the functions in Test::More.\n\nThey all return true if the test passed, false if the test failed.\n\n$name is always optional.\n\nok\n$Test->ok($test, $name);\n\nYour basic test.  Pass if $test is true, fail if $test is false.\nJust like Test::Simple's \"ok()\".\n\niseq\n$Test->iseq($got, $expected, $name);\n\nLike Test::More's \"is()\".  Checks if \"$got eq $expected\".  This is\nthe string version.\n\n\"undef\" only ever matches another \"undef\".\n\nisnum\n$Test->isnum($got, $expected, $name);\n\nLike Test::More's \"is()\".  Checks if \"$got == $expected\".  This is\nthe numeric version.\n\n\"undef\" only ever matches another \"undef\".\n\nisnteq\n$Test->isnteq($got, $dontexpect, $name);\n\nLike Test::More's \"isnt()\".  Checks if \"$got ne $dontexpect\".\nThis is the string version.\n\nisntnum\n$Test->isntnum($got, $dontexpect, $name);\n\nLike Test::More's \"isnt()\".  Checks if \"$got ne $dontexpect\".\nThis is the numeric version.\n\nlike\n$Test->like($thing, qr/$regex/, $name);\n$Test->like($thing, '/$regex/', $name);\n\nLike Test::More's \"like()\".  Checks if $thing matches the given\n$regex.\n\nunlike\n$Test->unlike($thing, qr/$regex/, $name);\n$Test->unlike($thing, '/$regex/', $name);\n\nLike Test::More's \"unlike()\".  Checks if $thing does not match the\ngiven $regex.\n\ncmpok\n$Test->cmpok($thing, $type, $that, $name);\n\nWorks just like Test::More's \"cmpok()\".\n\n$Test->cmpok($bignum, '!=', $otherbignum);\n\nOther Testing Methods\nThese are methods which are used in the course of writing a test but\nare not themselves tests.\n\nBAILOUT\n$Test->BAILOUT($reason);\n\nIndicates to the Test::Harness that things are going so badly all\ntesting should terminate.  This includes running any additional\ntest scripts.\n\nIt will exit with 255.\n\nskip\n$Test->skip;\n$Test->skip($why);\n\nSkips the current test, reporting $why.\n\ntodoskip\n$Test->todoskip;\n$Test->todoskip($why);\n\nLike \"skip()\", only it will declare the test as failing and TODO.\nSimilar to\n\nprint \"not ok $tnum # TODO $why\\n\";\n\nTest building utility methods\nThese methods are useful when writing your own test methods.\n\nmayberegex\n$Test->mayberegex(qr/$regex/);\n$Test->mayberegex('/$regex/');\n\nThis method used to be useful back when Test::Builder worked on\nPerls before 5.6 which didn't have qr//.  Now its pretty useless.\n\nConvenience method for building testing functions that take regular\nexpressions as arguments.\n\nTakes a quoted regular expression produced by \"qr//\", or a string\nrepresenting a regular expression.\n\nReturns a Perl value which may be used instead of the corresponding\nregular expression, or \"undef\" if its argument is not recognized.\n\nFor example, a version of \"like()\", sans the useful diagnostic\nmessages, could be written as:\n\nsub laconiclike {\nmy ($self, $thing, $regex, $name) = @;\nmy $usableregex = $self->mayberegex($regex);\ndie \"expecting regex, found '$regex'\\n\"\nunless $usableregex;\n$self->ok($thing =~ m/$usableregex/, $name);\n}\n\nisfh\nmy $isfh = $Test->isfh($thing);\n\nDetermines if the given $thing can be used as a filehandle.\n\nTest style\nlevel\n$Test->level($howhigh);\n\nHow far up the call stack should $Test look when reporting where\nthe test failed.\n\nDefaults to 1.\n\nSetting $Test::Builder::Level overrides.  This is typically useful\nlocalized:\n\nsub myok {\nmy $test = shift;\n\nlocal $Test::Builder::Level = $Test::Builder::Level + 1;\n$TB->ok($test);\n}\n\nTo be polite to other functions wrapping your own you usually want\nto increment $Level rather than set it to a constant.\n\nusenumbers\n$Test->usenumbers($onoroff);\n\nWhether or not the test should output numbers.  That is, this if\ntrue:\n\nok 1\nok 2\nok 3\n\nor this if false\n\nok\nok\nok\n\nMost useful when you can't depend on the test output order, such as\nwhen threads or forking is involved.\n\nDefaults to on.\n\nnodiag\n$Test->nodiag($nodiag);\n\nIf set true no diagnostics will be printed.  This includes calls to\n\"diag()\".\n\nnoending\n$Test->noending($noending);\n\nNormally, Test::Builder does some extra diagnostics when the test\nends.  It also changes the exit code as described below.\n\nIf this is true, none of that will be done.\n\nnoheader\n$Test->noheader($noheader);\n\nIf set to true, no \"1..N\" header will be printed.\n\nOutput\nControlling where the test output goes.\n\nIt's ok for your test to change where STDOUT and STDERR point to,\nTest::Builder's default output settings will not be affected.\n\ndiag\n$Test->diag(@msgs);\n\nPrints out the given @msgs.  Like \"print\", arguments are simply\nappended together.\n\nNormally, it uses the \"failureoutput()\" handle, but if this is for\na TODO test, the \"todooutput()\" handle is used.\n\nOutput will be indented and marked with a # so as not to interfere\nwith test output.  A newline will be put on the end if there isn't\none already.\n\nWe encourage using this rather than calling print directly.\n\nReturns false.  Why?  Because \"diag()\" is often used in conjunction\nwith a failing test (\"ok() || diag()\") it \"passes through\" the\nfailure.\n\nreturn ok(...) || diag(...);\n\nnote\n$Test->note(@msgs);\n\nLike \"diag()\", but it prints to the \"output()\" handle so it will\nnot normally be seen by the user except in verbose mode.\n\nexplain\nmy @dump = $Test->explain(@msgs);\n\nWill dump the contents of any references in a human readable\nformat.  Handy for things like...\n\nisdeeply($have, $want) || diag explain $have;\n\nor\n\nisdeeply($have, $want) || note explain $have;\n\noutput\nfailureoutput\ntodooutput\nmy $filehandle = $Test->output;\n$Test->output($filehandle);\n$Test->output($filename);\n$Test->output(\\$scalar);\n\nThese methods control where Test::Builder will print its output.\nThey take either an open $filehandle, a $filename to open and write\nto or a $scalar reference to append to.  It will always return a\n$filehandle.\n\noutput is where normal \"ok/not ok\" test output goes.\n\nDefaults to STDOUT.\n\nfailureoutput is where diagnostic output on test failures and\n\"diag()\" goes.  It is normally not read by Test::Harness and\ninstead is displayed to the user.\n\nDefaults to STDERR.\n\n\"todooutput\" is used instead of \"failureoutput()\" for the\ndiagnostics of a failing TODO test.  These will not be seen by the\nuser.\n\nDefaults to STDOUT.\n\nresetoutputs\n$tb->resetoutputs;\n\nResets all the output filehandles back to their defaults.\n\ncarp\n$tb->carp(@message);\n\nWarns with @message but the message will appear to come from the\npoint where the original test function was called (\"$tb->caller\").\n\ncroak\n$tb->croak(@message);\n\nDies with @message but the message will appear to come from the\npoint where the original test function was called (\"$tb->caller\").\n\nTest Status and Info\nnologresults\nThis will turn off result long-term storage. Calling this method\nwill make \"details\" and \"summary\" useless. You may want to use this\nif you are running enough tests to fill up all available memory.\n\nTest::Builder->new->nologresults();\n\nThere is no way to turn it back on.\n\ncurrenttest\nmy $currtest = $Test->currenttest;\n$Test->currenttest($num);\n\nGets/sets the current test number we're on.  You usually shouldn't\nhave to set this.\n\nIf set forward, the details of the missing tests are filled in as\n'unknown'.  if set backward, the details of the intervening tests\nare deleted.  You can erase history if you really want to.\n\nispassing\nmy $ok = $builder->ispassing;\n\nIndicates if the test suite is currently passing.\n\nMore formally, it will be false if anything has happened which\nmakes it impossible for the test suite to pass.  True otherwise.\n\nFor example, if no tests have run \"ispassing()\" will be true\nbecause even though a suite with no tests is a failure you can add\na passing test to it and start passing.\n\nDon't think about it too much.\n\nsummary\nmy @tests = $Test->summary;\n\nA simple summary of the tests so far.  True for pass, false for\nfail.  This is a logical pass/fail, so todos are passes.\n\nOf course, test #1 is $tests[0], etc...\n\ndetails\nmy @tests = $Test->details;\n\nLike \"summary()\", but with a lot more detail.\n\n$tests[$testnum - 1] =\n{ 'ok'       => is the test considered a pass?\nactualok  => did it literally say 'ok'?\nname       => name of the test (if any)\ntype       => type of test (if any, see below).\nreason     => reason for the above (if any)\n};\n\n'ok' is true if Test::Harness will consider the test to be a pass.\n\n'actualok' is a reflection of whether or not the test literally\nprinted 'ok' or 'not ok'.  This is for examining the result of\n'todo' tests.\n\n'name' is the name of the test.\n\n'type' indicates if it was a special test.  Normal tests have a\ntype of ''.  Type can be one of the following:\n\nskip        see skip()\ntodo        see todo()\ntodoskip   see todoskip()\nunknown     see below\n\nSometimes the Test::Builder test counter is incremented without it\nprinting any test output, for example, when \"currenttest()\" is\nchanged.  In these cases, Test::Builder doesn't know the result of\nthe test, so its type is 'unknown'.  These details for these tests\nare filled in.  They are considered ok, but the name and actualok\nis left \"undef\".\n\nFor example \"not ok 23 - hole count # TODO insufficient donuts\"\nwould result in this structure:\n\n$tests[22] =    # 23 - 1, since arrays start from 0.\n{ ok        => 1,   # logically, the test passed since its todo\nactualok => 0,   # in absolute terms, it failed\nname      => 'hole count',\ntype      => 'todo',\nreason    => 'insufficient donuts'\n};\n\ntodo\nmy $todoreason = $Test->todo;\nmy $todoreason = $Test->todo($pack);\n\nIf the current tests are considered \"TODO\" it will return the\nreason, if any.  This reason can come from a $TODO variable or the\nlast call to \"todostart()\".\n\nSince a TODO test does not need a reason, this function can return\nan empty string even when inside a TODO block.  Use\n\"$Test->intodo\" to determine if you are currently inside a TODO\nblock.\n\n\"todo()\" is about finding the right package to look for $TODO in.\nIt's pretty good at guessing the right package to look at.  It\nfirst looks for the caller based on \"$Level + 1\", since \"todo()\" is\nusually called inside a test function.  As a last resort it will\nuse \"exportedto()\".\n\nSometimes there is some confusion about where \"todo()\" should be\nlooking for the $TODO variable.  If you want to be sure, tell it\nexplicitly what $pack to use.\n\nfindTODO\nmy $todoreason = $Test->findTODO();\nmy $todoreason = $Test->findTODO($pack);\n\nLike \"todo()\" but only returns the value of $TODO ignoring\n\"todostart()\".\n\nCan also be used to set $TODO to a new value while returning the\nold value:\n\nmy $oldreason = $Test->findTODO($pack, 1, $newreason);\n\nintodo\nmy $intodo = $Test->intodo;\n\nReturns true if the test is currently inside a TODO block.\n\ntodostart\n$Test->todostart();\n$Test->todostart($message);\n\nThis method allows you declare all subsequent tests as TODO tests,\nup until the \"todoend\" method has been called.\n\nThe \"TODO:\" and $TODO syntax is generally pretty good about\nfiguring out whether or not we're in a TODO test.  However, often\nwe find that this is not possible to determine (such as when we\nwant to use $TODO but the tests are being executed in other\npackages which can't be inferred beforehand).\n\nNote that you can use this to nest \"todo\" tests\n\n$Test->todostart('working on this');\n# lots of code\n$Test->todostart('working on that');\n# more code\n$Test->todoend;\n$Test->todoend;\n\nThis is generally not recommended, but large testing systems often\nhave weird internal needs.\n\nWe've tried to make this also work with the TODO: syntax, but it's\nnot guaranteed and its use is also discouraged:\n\nTODO: {\nlocal $TODO = 'We have work to do!';\n$Test->todostart('working on this');\n# lots of code\n$Test->todostart('working on that');\n# more code\n$Test->todoend;\n$Test->todoend;\n}\n\nPick one style or another of \"TODO\" to be on the safe side.\n\n\"todoend\"\n$Test->todoend;\n\nStops running tests as \"TODO\" tests.  This method is fatal if\ncalled without a preceding \"todostart\" method call.\n\ncaller\nmy $package = $Test->caller;\nmy($pack, $file, $line) = $Test->caller;\nmy($pack, $file, $line) = $Test->caller($height);\n\nLike the normal \"caller()\", except it reports according to your\n\"level()\".\n\n$height will be added to the \"level()\".\n\nIf \"caller()\" winds up off the top of the stack it report the\nhighest context.\n",
                "subsections": []
            },
            "EXIT CODES": {
                "content": "If all your tests passed, Test::Builder will exit with zero (which is\nnormal).  If anything failed it will exit with how many failed.  If you\nrun less (or more) tests than you planned, the missing (or extras) will\nbe considered failures.  If no tests were ever run Test::Builder will\nthrow a warning and exit with 255.  If the test died, even after having\nsuccessfully completed all its tests, it will still be considered a\nfailure and will exit with 255.\n\nSo the exit codes are...\n\n0                   all tests successful\n255                 test died or all passed but wrong # of tests run\nany other number    how many failed (including missing or extras)\n\nIf you fail more than 254 tests, it will be reported as 254.\n",
                "subsections": []
            },
            "THREADS": {
                "content": "In perl 5.8.1 and later, Test::Builder is thread-safe.  The test number\nis shared by all threads.  This means if one thread sets the test\nnumber using \"currenttest()\" they will all be effected.\n\nWhile versions earlier than 5.8.1 had threads they contain too many\nbugs to support.\n\nTest::Builder is only thread-aware if threads.pm is loaded before\nTest::Builder.\n\nYou can directly disable thread support with one of the following:\n\n$ENV{T2NOIPC} = 1\n\nor\n\nno Test2::IPC;\n\nor\n\nTest2::API::test2ipcdisable()\n",
                "subsections": []
            },
            "MEMORY": {
                "content": "An informative hash, accessible via \"details()\", is stored for each\ntest you perform.  So memory usage will scale linearly with each test\nrun. Although this is not a problem for most test suites, it can become\nan issue if you do large (hundred thousands to million) combinatorics\ntests in the same run.\n\nIn such cases, you are advised to either split the test file into\nsmaller ones, or use a reverse approach, doing \"normal\" (code) compares\nand triggering \"fail()\" should anything go unexpected.\n\nFuture versions of Test::Builder will have a way to turn history off.\n",
                "subsections": []
            },
            "EXAMPLES": {
                "content": "CPAN can provide the best examples.  Test::Simple, Test::More,\nTest::Exception and Test::Differences all use Test::Builder.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "INTERNALS\nTest2, Test2::API\n\nLEGACY\nTest::Simple, Test::More\n\nEXTERNAL\nTest::Harness\n",
                "subsections": []
            },
            "AUTHORS": {
                "content": "Original code by chromatic, maintained by Michael G Schwern\n<schwern@pobox.com>\n",
                "subsections": []
            },
            "MAINTAINERS": {
                "content": "Chad Granum <exodist@cpan.org>\n",
                "subsections": []
            },
            "COPYRIGHT": {
                "content": "Copyright 2002-2008 by chromatic <chromatic@wgz.org> and\nMichael G Schwern <schwern@pobox.com>.\n\nThis program is free software; you can redistribute it and/or modify it\nunder the same terms as Perl itself.\n\nSee http://www.perl.com/perl/misc/Artistic.html\n\nperl v5.34.0                      2026-06-23              Test::Builder(3perl)",
                "subsections": []
            }
        }
    }
}