Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / man / man3 / Test::Builder.3
.\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sh \" Subsection heading
.br
.if t .Sp
.ne 5
.PP
\fB\\$1\fR
.PP
..
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" 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<>.
.tr \(*W-|\(bv\*(Tr
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. 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
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
'br\}
.\"
.\" 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.
.if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. nr % 0
. rr F
.\}
.\"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.hy 0
.if n .na
.\"
.\" 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
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. 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 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "Test::Builder 3"
.TH Test::Builder 3 "2002-06-01" "perl v5.8.0" "Perl Programmers Reference Guide"
.SH "NAME"
Test::Builder \- Backend for building test libraries
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 5
\& package My::Test::Module;
\& use Test::Builder;
\& require Exporter;
\& @ISA = qw(Exporter);
\& @EXPORT = qw(ok);
.Ve
.PP
.Vb 2
\& my $Test = Test::Builder->new;
\& $Test->output('my_logfile');
.Ve
.PP
.Vb 3
\& sub import {
\& my($self) = shift;
\& my $pack = caller;
.Ve
.PP
.Vb 2
\& $Test->exported_to($pack);
\& $Test->plan(@_);
.Ve
.PP
.Vb 2
\& $self->export_to_level(1, $self, 'ok');
\& }
.Ve
.PP
.Vb 2
\& sub ok {
\& my($test, $name) = @_;
.Ve
.PP
.Vb 2
\& $Test->ok($test, $name);
\& }
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
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
work together\fR.
.Sh "Construction"
.IX Subsection "Construction"
.IP "\fBnew\fR" 4
.IX Item "new"
.Vb 1
\& my $Test = Test::Builder->new;
.Ve
.Sp
Returns a Test::Builder object representing the current state of the
test.
.Sp
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).
.Sh "Setting up tests"
.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
.IX Item "exported_to"
.Vb 2
\& my $pack = $Test->exported_to;
\& $Test->exported_to($pack);
.Ve
.Sp
Tells Test::Builder what package you exported your functions to.
This is important for getting \s-1TODO\s0 tests right.
.IP "\fBplan\fR" 4
.IX Item "plan"
.Vb 3
\& $Test->plan('no_plan');
\& $Test->plan( skip_all => $reason );
\& $Test->plan( tests => $num_tests );
.Ve
.Sp
A convenient way to set up your tests. Call this and Test::Builder
will print the appropriate headers and take the appropriate actions.
.Sp
If you call \fIplan()\fR, don't call any of the other methods below.
.IP "\fBexpected_tests\fR" 4
.IX Item "expected_tests"
.Vb 2
\& my $max = $Test->expected_tests;
\& $Test->expected_tests($max);
.Ve
.Sp
Gets/sets the # of tests we expect this test to run and prints out
the appropriate headers.
.IP "\fBno_plan\fR" 4
.IX Item "no_plan"
.Vb 1
\& $Test->no_plan;
.Ve
.Sp
Declares that this test will run an indeterminate # of tests.
.IP "\fBskip_all\fR" 4
.IX Item "skip_all"
.Vb 2
\& $Test->skip_all;
\& $Test->skip_all($reason);
.Ve
.Sp
Skips all the tests, using the given \f(CW$reason\fR. Exits immediately with 0.
.Sh "Running tests"
.IX Subsection "Running tests"
These actually run the tests, analogous to the functions in
Test::More.
.PP
$name is always optional.
.IP "\fBok\fR" 4
.IX Item "ok"
.Vb 1
\& $Test->ok($test, $name);
.Ve
.Sp
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.
.IP "\fBis_eq\fR" 4
.IX Item "is_eq"
.Vb 1
\& $Test->is_eq($got, $expected, $name);
.Ve
.Sp
Like Test::More's \fIis()\fR. Checks if \f(CW$got\fR eq \f(CW$expected\fR. This is the
string version.
.IP "\fBis_num\fR" 4
.IX Item "is_num"
.Vb 1
\& $Test->is_num($got, $expected, $name);
.Ve
.Sp
Like Test::More's \fIis()\fR. Checks if \f(CW$got\fR == \f(CW$expected\fR. This is the
numeric version.
.IP "\fBisnt_eq\fR" 4
.IX Item "isnt_eq"
.Vb 1
\& $Test->isnt_eq($got, $dont_expect, $name);
.Ve
.Sp
Like Test::More's \fIisnt()\fR. Checks if \f(CW$got\fR ne \f(CW$dont_expect\fR. This is
the string version.
.IP "\fBisnt_num\fR" 4
.IX Item "isnt_num"
.Vb 1
\& $Test->is_num($got, $dont_expect, $name);
.Ve
.Sp
Like Test::More's \fIisnt()\fR. Checks if \f(CW$got\fR ne \f(CW$dont_expect\fR. This is
the numeric version.
.IP "\fBlike\fR" 4
.IX Item "like"
.Vb 2
\& $Test->like($this, qr/$regex/, $name);
\& $Test->like($this, '/$regex/', $name);
.Ve
.Sp
Like Test::More's \fIlike()\fR. Checks if \f(CW$this\fR matches the given \f(CW$regex\fR.
.Sp
You'll want to avoid qr// if you want your tests to work before 5.005.
.IP "\fBunlike\fR" 4
.IX Item "unlike"
.Vb 2
\& $Test->unlike($this, qr/$regex/, $name);
\& $Test->unlike($this, '/$regex/', $name);
.Ve
.Sp
Like Test::More's \fIunlike()\fR. Checks if \f(CW$this\fR \fBdoes not match\fR the
given \f(CW$regex\fR.
.IP "\fBmaybe_regex\fR" 4
.IX Item "maybe_regex"
.Vb 2
\& $Test->maybe_regex(qr/$regex/);
\& $Test->maybe_regex('/$regex/');
.Ve
.Sp
Convenience method for building testing functions that take regular
expressions as arguments, but need to work before perl 5.005.
.Sp
Takes a quoted regular expression produced by qr//, or a string
representing a regular expression.
.Sp
Returns a Perl value which may be used instead of the corresponding
regular expression, or undef if it's argument is not recognised.
.Sp
For example, a version of \fIlike()\fR, sans the useful diagnostic messages,
could be written as:
.Sp
.Vb 7
\& sub laconic_like {
\& my ($self, $this, $regex, $name) = @_;
\& my $usable_regex = $self->maybe_regex($regex);
\& die "expecting regex, found '$regex'\en"
\& unless $usable_regex;
\& $self->ok($this =~ m/$usable_regex/, $name);
\& }
.Ve
.IP "\fBcmp_ok\fR" 4
.IX Item "cmp_ok"
.Vb 1
\& $Test->cmp_ok($this, $type, $that, $name);
.Ve
.Sp
Works just like Test::More's \fIcmp_ok()\fR.
.Sp
.Vb 1
\& $Test->cmp_ok($big_num, '!=', $other_big_num);
.Ve
.IP "\fB\s-1BAILOUT\s0\fR" 4
.IX Item "BAILOUT"
.Vb 1
\& $Test->BAILOUT($reason);
.Ve
.Sp
Indicates to the Test::Harness that things are going so badly all
testing should terminate. This includes running any additional test
scripts.
.Sp
It will exit with 255.
.IP "\fBskip\fR" 4
.IX Item "skip"
.Vb 2
\& $Test->skip;
\& $Test->skip($why);
.Ve
.Sp
Skips the current test, reporting \f(CW$why\fR.
.IP "\fBtodo_skip\fR" 4
.IX Item "todo_skip"
.Vb 2
\& $Test->todo_skip;
\& $Test->todo_skip($why);
.Ve
.Sp
Like \fIskip()\fR, only it will declare the test as failing and \s-1TODO\s0. Similar
to
.Sp
.Vb 1
\& print "not ok $tnum # TODO $why\en";
.Ve
.Sh "Test style"
.IX Subsection "Test style"
.IP "\fBlevel\fR" 4
.IX Item "level"
.Vb 1
\& $Test->level($how_high);
.Ve
.Sp
How far up the call stack should \f(CW$Test\fR look when reporting where the
test failed.
.Sp
Defaults to 1.
.Sp
Setting \f(CW$Test::Builder::Level\fR overrides. This is typically useful
localized:
.Sp
.Vb 4
\& {
\& local $Test::Builder::Level = 2;
\& $Test->ok($test);
\& }
.Ve
.IP "\fBuse_numbers\fR" 4
.IX Item "use_numbers"
.Vb 1
\& $Test->use_numbers($on_or_off);
.Ve
.Sp
Whether or not the test should output numbers. That is, this if true:
.Sp
.Vb 3
\& ok 1
\& ok 2
\& ok 3
.Ve
.Sp
or this if false
.Sp
.Vb 3
\& ok
\& ok
\& ok
.Ve
.Sp
Most useful when you can't depend on the test output order, such as
when threads or forking is involved.
.Sp
Test::Harness will accept either, but avoid mixing the two styles.
.Sp
Defaults to on.
.IP "\fBno_header\fR" 4
.IX Item "no_header"
.Vb 1
\& $Test->no_header($no_header);
.Ve
.Sp
If set to true, no \*(L"1..N\*(R" header will be printed.
.IP "\fBno_ending\fR" 4
.IX Item "no_ending"
.Vb 1
\& $Test->no_ending($no_ending);
.Ve
.Sp
Normally, Test::Builder does some extra diagnostics when the test
ends. It also changes the exit code as described in Test::Simple.
.Sp
If this is true, none of that will be done.
.Sh "Output"
.IX Subsection "Output"
Controlling where the test output goes.
.PP
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.
.IP "\fBdiag\fR" 4
.IX Item "diag"
.Vb 1
\& $Test->diag(@msgs);
.Ve
.Sp
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
used.
.Sp
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
already.
.Sp
We encourage using this rather than calling print directly.
.Sp
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.
.Sp
.Vb 1
\& return ok(...) || diag(...);
.Ve
.IP "\fBoutput\fR" 4
.IX Item "output"
.Vb 2
\& $Test->output($fh);
\& $Test->output($file);
.Ve
.Sp
Where normal \*(L"ok/not ok\*(R" test output should go.
.Sp
Defaults to \s-1STDOUT\s0.
.IP "\fBfailure_output\fR" 4
.IX Item "failure_output"
.Vb 2
\& $Test->failure_output($fh);
\& $Test->failure_output($file);
.Ve
.Sp
Where diagnostic output on test failures and \fIdiag()\fR should go.
.Sp
Defaults to \s-1STDERR\s0.
.IP "\fBtodo_output\fR" 4
.IX Item "todo_output"
.Vb 2
\& $Test->todo_output($fh);
\& $Test->todo_output($file);
.Ve
.Sp
Where diagnostics about todo test failures and \fIdiag()\fR should go.
.Sp
Defaults to \s-1STDOUT\s0.
.Sh "Test Status and Info"
.IX Subsection "Test Status and Info"
.IP "\fBcurrent_test\fR" 4
.IX Item "current_test"
.Vb 2
\& my $curr_test = $Test->current_test;
\& $Test->current_test($num);
.Ve
.Sp
Gets/sets the current test # we're on.
.Sp
You usually shouldn't have to set this.
.IP "\fBsummary\fR" 4
.IX Item "summary"
.Vb 1
\& my @tests = $Test->summary;
.Ve
.Sp
A simple summary of the tests so far. True for pass, false for fail.
This is a logical pass/fail, so todos are passes.
.Sp
Of course, test #1 is \f(CW$tests\fR[0], etc...
.IP "\fBdetails\fR \fI\s-1UNIMPLEMENTED\s0\fR" 4
.IX Item "details UNIMPLEMENTED"
.Vb 1
\& my @tests = $Test->details;
.Ve
.Sp
Like \fIsummary()\fR, but with a lot more detail.
.Sp
.Vb 7
\& $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)
\& };
.Ve
.IP "\fBtodo\fR" 4
.IX Item "todo"
.Vb 2
\& my $todo_reason = $Test->todo;
\& my $todo_reason = $Test->todo($pack);
.Ve
.Sp
\&\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.
.Sp
\&\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.
.Sp
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.
.IP "\fBcaller\fR" 4
.IX Item "caller"
.Vb 3
\& my $package = $Test->caller;
\& my($pack, $file, $line) = $Test->caller;
\& my($pack, $file, $line) = $Test->caller($height);
.Ve
.Sp
Like the normal \fIcaller()\fR, except it reports according to your \fIlevel()\fR.
.SH "THREADS"
.IX Header "THREADS"
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.
.SH "EXAMPLES"
.IX Header "EXAMPLES"
\&\s-1CPAN\s0 can provide the best examples. Test::Simple, Test::More,
Test::Exception and Test::Differences all use Test::Builder.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
Test::Simple, Test::More, Test::Harness
.SH "AUTHORS"
.IX Header "AUTHORS"
Original code by chromatic, maintained by Michael G Schwern
<schwern@pobox.com>
.SH "COPYRIGHT"
.IX Header "COPYRIGHT"
Copyright 2001 by chromatic <chromatic@wgz.org>,
Michael G Schwern <schwern@pobox.com>.
.PP
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
.PP
See \fIhttp://www.perl.com/perl/misc/Artistic.html\fR