TEST::BUILDER::TESTER(3perl)

πŸ’– Test::Builder::Tester β€” the 3perl page, but make it cute ✨

okay bestie so you're reading the Perl Programmers Reference Guide and this little diva right here is called Test::Builder::Tester β€” literally a module for testing your testsuites that were built with Test::Builder. yes we're testing the tests. it's meta, it's iconic, we love it πŸ’…


🌸 NAME 🌸

Test::Builder::Tester β€” test testsuites that have been built with Test::Builder 🫢


✨ SYNOPSIS ✨

use Test::Builder::Tester tests => 1;
use Test::More;

test_out("not ok 1 - foo");
test_fail(+1);
fail("foo");
test_test("fail works");

πŸ¦‹ DESCRIPTION πŸ¦‹

k so this module is for helping you test testing modules that got built with Test::Builder. very inception of it all.

the vibe is a three step process for every single test you wanna test, no skips:

  1. First up, you use test_out and test_err in advance to declare what the testsuite you're testing is gonna output to stdout and stderr.
  2. Then you run the actual test(s) from your suite that call Test::Builder. and here's the slay part β€” the output of Test::Builder is safely captured by Test::Builder::Tester instead of being read as real test output πŸ‘‘
  3. Final stage: call test_test, which just compares what you predeclared against what Test::Builder actually outputted, and reports the results back to normal output with a ok or not ok (with debugging, bestie).

πŸ’• Functions πŸ’•

these are the six methods that are exported as default btw.

🌷 test_out / test_err

procedures for predeclaring the output your test suite is expected to produce until test_test is called. these automatically assume each line terminates with "\n". so:

test_out("ok 1","ok 2");

is literally the same as:

test_out("ok 1\nok 2");

which is even the same as:

test_out("ok 1");
test_out("ok 2");

periodt. πŸ’…

once test_out or test_err (or test_fail or test_diag) have been called, all further output from Test::Builder gets captured by Test::Builder::Tester. which means you will not be able to do further tests to the normal output in the normal way until you call test_test β€” well, unless you manually meddle with the output filehandles, but like, that's a you problem πŸ™ˆ

🌷 test_fail

so the standard failure message that Test::Builder produces whenever a test fails is gonna show up a lot</em> in your test error output, and it's also changed between Test::Builder versions. so instead of forcing you to call test_err with the whole string every single time like:

test_err("# Failed test ($0 at line ".line_num(+1).")");

test_fail exists as a convenience function you can call instead πŸŽ€ it takes one argument: the offset from the current line that the line causing the fail is on.

test_fail(+1);

so the example in the synopsis? could be rewritten more simply as:

test_out("not ok 1 - foo");
test_fail(+1);
fail("foo");
test_test("fail works");

chef's kiss πŸ§‘β€πŸ³

🌷 test_diag

most of the remaining expected output to the error stream is gonna be created by Test::Builder's diag function, so Test::Builder::Tester provides a convenience function test_diag you can use instead of test_err.

test_diag prepends comment hashes and spacing to the start, and newlines to the end of the expected output passed to it, and adds it to the list of expected error output. so instead of writing:

test_err("# Couldn't open file");

you can write:

test_diag("Couldn't open file");

and honestly? obsessed. ✨

remember that Test::Builder's diag function will not add newlines to the end of output, and test_diag will. so to check:

Test::Builder->new->diag("foo\n","bar\n");

you would do:

test_diag("foo","bar")

without the newlines, bestie. don't add them. i'm serious. 😭

🌷 test_test

this one actually performs the output check β€” testing the tests, comparing the data (with eq, no cap) that we captured from Test::Builder against what was declared with test_out and test_err.

it takes name/value pairs that affect how the test is run:

  • title (synonym 'name', 'label') β€” the name of the test that'll be displayed after the ok or not ok.
  • skip_out β€” set this to a true value and the test will ignore it if the output sent by the test to the output stream doesn't match what was declared with test_out.
  • skip_err β€” set this to a true value and the test will ignore it if the output sent by the test to the error stream doesn't match what was declared with test_err.

as a convenience, if only one argument is passed, then that argument is assumed to be the name of the test (as in the examples above). slay.

once test_test has been run, test output gets redirected back to the original filehandles that Test::Builder was connected to (probably STDOUT and STDERR), meaning any further tests you run will function normally and cause success/errors for Test::Harness. we back, baby πŸ’–

🌷 line_num

a utility function that returns the line number the function was called on. you can pass it an offset which gets added to the result. super useful for working out the correct text of diagnostic functions that contain line numbers.

essentially this is the same as the __LINE__ macro, but the line_num(+3) idiom is arguably nicer. πŸ’…


in addition to the six exported functions, there exists one function that can only be accessed with a fully qualified function call.

🌷 color

when test_test is called and the output your tests generate doesn't match what you declared, test_test prints out debug information showing the two conflicting versions. and since this output is itself debug info, it can get confusing figuring out which part is from test_test and which was the original output from your original tests. also it can be hard to spot things like extraneous whitespace at the end of lines that may cause your test to fail even though the output looks similar. 😭

to assist you, test_test can colour the background of the debug information to disambiguate the different types of output. the debug output has its background coloured green and red. the green part represents the text that's the same between the executed and actual output, and the red shows which part differs.

the color function determines whether colouring should occur or not. passing it a true or false value enables or disables colouring respectively, and the function called with no argument returns the current setting.

to enable colouring from the command line, you can use the Text::Builder::Tester::Color module like so:

perl -Mlib=Text::Builder::Tester::Color test.t

or by including the Test::Builder::Tester::Color module directly in the PERL5LIB. whatever floats your boat πŸ¦‹


πŸ’€ BUGS πŸ’€

ok so Test::Builder::Tester does not handle plans well. it has never done anything special with plans. this means plans from outside Test::Builder::Tester will affect Test::Builder::Tester, and β€” worse β€” plans when using Test::Builder::Tester will affect overall testing. 😭 at this point there are no plans to fix this bug as people have come to depend on it, and Test::Builder::Tester is now discouraged in favor of Test2::API::intercept(). see <https://github.com/Test-More/test-more/issues/667>

it calls Test::Builder->no_ending, turning off the ending tests. this is needed because otherwise it will trip out, since we've run more tests than we strictly should have, and it'll register any failures we had that we were testing for as real failures.

the color function doesn't work unless Term::ANSIColor is compatible with your terminal. additionally, Win32::Console::ANSI must be installed on windows platforms for color output. πŸ™ˆ

bugs (and requests for new features) can be reported to the author through GitHub: <https://github.com/Test-More/test-more/issues>


πŸ‘‘ AUTHOR πŸ‘‘

Copyright Mark Fowler <mark@twoshortplanks.com> 2002, 2004.

some code taken from Test::More and Test::Catch, written by Michael G Schwern <schwern@pobox.com>. hence, those parts Copyright Micheal G Schwern 2001. used and distributed with permission.

this program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


🌈 MAINTAINERS 🌈

Chad Granum <exodist@cpan.org>


πŸŽ€ NOTES πŸŽ€

thanks to Richard Clamp <richardc@unixbeard.net> for letting me use his testing system to try this module out on. 🫢


🌸 SEE ALSO 🌸

Test::Builder, Test::Builder::Tester::Color, Test::More.


and that's the whole page bestie!! πŸ’– this one's from perl v5.44.0, dated 2026-10-17, and it's the Test::...:Tester(3perl) joint. go test your tests, you absolute icon πŸ‘‘βœ¨πŸ¦‹

πŸ“¦ where this page comes from
  • arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms