.\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13
.\" ========================================================================
.de Sh \" Subsection heading
.de Sp \" Vertical space (when we can't use .PP)
.de Vb \" Begin verbatim text
.de Ve \" End verbatim text
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. | will give a
.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
.\" expand to `' in nroff, nothing in troff, for use with C<>.
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
. tm Index:\\$1\t\\n%\t"\\$2"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. \" simple accents for nroff and troff
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
. \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
.\" ========================================================================
.IX Title "Test::Builder 3"
.TH Test::Builder 3 "2002-06-01" "perl v5.8.0" "Perl Programmers Reference Guide"
Test::Builder \- Backend for building test libraries
\& package My::Test::Module;
\& my $Test = Test::Builder->new;
\& $Test->output('my_logfile');
\& $Test->exported_to($pack);
\& $self->export_to_level(1, $self, 'ok');
\& my($test, $name) = @_;
\& $Test->ok($test, $name);
Test::Simple and Test::More have proven to be popular testing modules,
but they're not always flexible enough. Test::Builder provides the a
building block upon which to write your own test libraries \fIwhich can
.IX Subsection "Construction"
\& my $Test = Test::Builder->new;
Returns a Test::Builder object representing the current state of the
Since you only run one test per program, there is \fBone and only one\fR
Test::Builder object. No matter how many times you call \fInew()\fR, you're
getting the same object. (This is called a singleton).
.IX Subsection "Setting up tests"
These methods are for setting up tests and declaring how many there
are. You usually only want to call one of these methods.
.IP "\fBexported_to\fR" 4
\& my $pack = $Test->exported_to;
\& $Test->exported_to($pack);
Tells Test::Builder what package you exported your functions to.
This is important for getting \s-1TODO\s0 tests right.
\& $Test->plan('no_plan');
\& $Test->plan( skip_all => $reason );
\& $Test->plan( tests => $num_tests );
A convenient way to set up your tests. Call this and Test::Builder
will print the appropriate headers and take the appropriate actions.
If you call \fIplan()\fR, don't call any of the other methods below.
.IP "\fBexpected_tests\fR" 4
.IX Item "expected_tests"
\& my $max = $Test->expected_tests;
\& $Test->expected_tests($max);
Gets/sets the # of tests we expect this test to run and prints out
Declares that this test will run an indeterminate # of tests.
\& $Test->skip_all($reason);
Skips all the tests, using the given \f(CW$reason\fR. Exits immediately with 0.
.IX Subsection "Running tests"
These actually run the tests, analogous to the functions in
$name is always optional.
\& $Test->ok($test, $name);
Your basic test. Pass if \f(CW$test\fR is true, fail if \f(CW$test\fR is false. Just
like Test::Simple's \fIok()\fR.
\& $Test->is_eq($got, $expected, $name);
Like Test::More's \fIis()\fR. Checks if \f(CW$got\fR eq \f(CW$expected\fR. This is the
\& $Test->is_num($got, $expected, $name);
Like Test::More's \fIis()\fR. Checks if \f(CW$got\fR == \f(CW$expected\fR. This is the
\& $Test->isnt_eq($got, $dont_expect, $name);
Like Test::More's \fIisnt()\fR. Checks if \f(CW$got\fR ne \f(CW$dont_expect\fR. This is
\& $Test->is_num($got, $dont_expect, $name);
Like Test::More's \fIisnt()\fR. Checks if \f(CW$got\fR ne \f(CW$dont_expect\fR. This is
\& $Test->like($this, qr/$regex/, $name);
\& $Test->like($this, '/$regex/', $name);
Like Test::More's \fIlike()\fR. Checks if \f(CW$this\fR matches the given \f(CW$regex\fR.
You'll want to avoid qr// if you want your tests to work before 5.005.
\& $Test->unlike($this, qr/$regex/, $name);
\& $Test->unlike($this, '/$regex/', $name);
Like Test::More's \fIunlike()\fR. Checks if \f(CW$this\fR \fBdoes not match\fR the
.IP "\fBmaybe_regex\fR" 4
\& $Test->maybe_regex(qr/$regex/);
\& $Test->maybe_regex('/$regex/');
Convenience method for building testing functions that take regular
expressions as arguments, but need to work before perl 5.005.
Takes a quoted regular expression produced by qr//, or a string
representing a regular expression.
Returns a Perl value which may be used instead of the corresponding
regular expression, or undef if it's argument is not recognised.
For example, a version of \fIlike()\fR, sans the useful diagnostic messages,
\& my ($self, $this, $regex, $name) = @_;
\& my $usable_regex = $self->maybe_regex($regex);
\& die "expecting regex, found '$regex'\en"
\& $self->ok($this =~ m/$usable_regex/, $name);
\& $Test->cmp_ok($this, $type, $that, $name);
Works just like Test::More's \fIcmp_ok()\fR.
\& $Test->cmp_ok($big_num, '!=', $other_big_num);
.IP "\fB\s-1BAILOUT\s0\fR" 4
\& $Test->BAILOUT($reason);
Indicates to the Test::Harness that things are going so badly all
testing should terminate. This includes running any additional test
Skips the current test, reporting \f(CW$why\fR.
\& $Test->todo_skip($why);
Like \fIskip()\fR, only it will declare the test as failing and \s-1TODO\s0. Similar
\& print "not ok $tnum # TODO $why\en";
.IX Subsection "Test style"
\& $Test->level($how_high);
How far up the call stack should \f(CW$Test\fR look when reporting where the
Setting \f(CW$Test::Builder::Level\fR overrides. This is typically useful
\& local $Test::Builder::Level = 2;
.IP "\fBuse_numbers\fR" 4
\& $Test->use_numbers($on_or_off);
Whether or not the test should output numbers. That is, this if true:
Most useful when you can't depend on the test output order, such as
when threads or forking is involved.
Test::Harness will accept either, but avoid mixing the two styles.
\& $Test->no_header($no_header);
If set to true, no \*(L"1..N\*(R" header will be printed.
\& $Test->no_ending($no_ending);
Normally, Test::Builder does some extra diagnostics when the test
ends. It also changes the exit code as described in Test::Simple.
If this is true, none of that will be done.
Controlling where the test output goes.
It's ok for your test to change where \s-1STDOUT\s0 and \s-1STDERR\s0 point to,
Test::Builder's default output settings will not be affected.
Prints out the given \f(CW$message\fR. Normally, it uses the \fIfailure_output()\fR
handle, but if this is for a \s-1TODO\s0 test, the \fItodo_output()\fR handle is
Output will be indented and marked with a # so as not to interfere
with test output. A newline will be put on the end if there isn't one
We encourage using this rather than calling print directly.
Returns false. Why? Because \fIdiag()\fR is often used in conjunction with
a failing test (\f(CW\*(C`ok() || diag()\*(C'\fR) it \*(L"passes through\*(R" the failure.
\& return ok(...) || diag(...);
Where normal \*(L"ok/not ok\*(R" test output should go.
Defaults to \s-1STDOUT\s0.
.IP "\fBfailure_output\fR" 4
.IX Item "failure_output"
\& $Test->failure_output($fh);
\& $Test->failure_output($file);
Where diagnostic output on test failures and \fIdiag()\fR should go.
Defaults to \s-1STDERR\s0.
.IP "\fBtodo_output\fR" 4
\& $Test->todo_output($fh);
\& $Test->todo_output($file);
Where diagnostics about todo test failures and \fIdiag()\fR should go.
Defaults to \s-1STDOUT\s0.
.Sh "Test Status and Info"
.IX Subsection "Test Status and Info"
.IP "\fBcurrent_test\fR" 4
\& my $curr_test = $Test->current_test;
\& $Test->current_test($num);
Gets/sets the current test # we're on.
You usually shouldn't have to set this.
\& my @tests = $Test->summary;
A simple summary of the tests so far. True for pass, false for fail.
This is a logical pass/fail, so todos are passes.
Of course, test #1 is \f(CW$tests\fR[0], etc...
.IP "\fBdetails\fR \fI\s-1UNIMPLEMENTED\s0\fR" 4
.IX Item "details UNIMPLEMENTED"
\& my @tests = $Test->details;
Like \fIsummary()\fR, but with a lot more detail.
\& $tests[$test_num - 1] =
\& { ok => is the test considered ok?
\& actual_ok => did it literally say 'ok'?
\& name => name of the test (if any)
\& type => 'skip' or 'todo' (if any)
\& reason => reason for the above (if any)
\& my $todo_reason = $Test->todo;
\& my $todo_reason = $Test->todo($pack);
\&\fItodo()\fR looks for a \f(CW$TODO\fR variable in your tests. If set, all tests
will be considered 'todo' (see Test::More and Test::Harness for
details). Returns the reason (ie. the value of \f(CW$TODO\fR) if running as
todo tests, false otherwise.
\&\fItodo()\fR is pretty part about finding the right package to look for
\&\f(CW$TODO\fR in. It uses the \fIexported_to()\fR package to find it. If that's
not set, it's pretty good at guessing the right package to look at.
Sometimes there is some confusion about where \fItodo()\fR should be looking
for the \f(CW$TODO\fR variable. If you want to be sure, tell it explicitly
what \f(CW$pack\fR to use.
\& my $package = $Test->caller;
\& my($pack, $file, $line) = $Test->caller;
\& my($pack, $file, $line) = $Test->caller($height);
Like the normal \fIcaller()\fR, except it reports according to your \fIlevel()\fR.
In perl 5.8.0 and later, Test::Builder is thread\-safe. The test
number is shared amongst all threads. This means if one thread sets
the test number using \fIcurrent_test()\fR they will all be effected.
\&\s-1CPAN\s0 can provide the best examples. Test::Simple, Test::More,
Test::Exception and Test::Differences all use Test::Builder.
Test::Simple, Test::More, Test::Harness
Original code by chromatic, maintained by Michael G Schwern
Copyright 2001 by chromatic <chromatic@wgz.org>,
Michael G Schwern <schwern@pobox.com>.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
See \fIhttp://www.perl.com/perl/misc/Artistic.html\fR