Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 |
2 | .\" | |
3 | .\" Standard preamble: | |
4 | .\" ======================================================================== | |
5 | .de Sh \" Subsection heading | |
6 | .br | |
7 | .if t .Sp | |
8 | .ne 5 | |
9 | .PP | |
10 | \fB\\$1\fR | |
11 | .PP | |
12 | .. | |
13 | .de Sp \" Vertical space (when we can't use .PP) | |
14 | .if t .sp .5v | |
15 | .if n .sp | |
16 | .. | |
17 | .de Vb \" Begin verbatim text | |
18 | .ft CW | |
19 | .nf | |
20 | .ne \\$1 | |
21 | .. | |
22 | .de Ve \" End verbatim text | |
23 | .ft R | |
24 | .fi | |
25 | .. | |
26 | .\" Set up some character translations and predefined strings. \*(-- will | |
27 | .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left | |
28 | .\" double quote, and \*(R" will give a right double quote. | will give a | |
29 | .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to | |
30 | .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' | |
31 | .\" expand to `' in nroff, nothing in troff, for use with C<>. | |
32 | .tr \(*W-|\(bv\*(Tr | |
33 | .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' | |
34 | .ie n \{\ | |
35 | . ds -- \(*W- | |
36 | . ds PI pi | |
37 | . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch | |
38 | . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch | |
39 | . ds L" "" | |
40 | . ds R" "" | |
41 | . ds C` "" | |
42 | . ds C' "" | |
43 | 'br\} | |
44 | .el\{\ | |
45 | . ds -- \|\(em\| | |
46 | . ds PI \(*p | |
47 | . ds L" `` | |
48 | . ds R" '' | |
49 | 'br\} | |
50 | .\" | |
51 | .\" If the F register is turned on, we'll generate index entries on stderr for | |
52 | .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index | |
53 | .\" entries marked with X<> in POD. Of course, you'll have to process the | |
54 | .\" output yourself in some meaningful fashion. | |
55 | .if \nF \{\ | |
56 | . de IX | |
57 | . tm Index:\\$1\t\\n%\t"\\$2" | |
58 | .. | |
59 | . nr % 0 | |
60 | . rr F | |
61 | .\} | |
62 | .\" | |
63 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes | |
64 | .\" way too many mistakes in technical documents. | |
65 | .hy 0 | |
66 | .if n .na | |
67 | .\" | |
68 | .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). | |
69 | .\" Fear. Run. Save yourself. No user-serviceable parts. | |
70 | . \" fudge factors for nroff and troff | |
71 | .if n \{\ | |
72 | . ds #H 0 | |
73 | . ds #V .8m | |
74 | . ds #F .3m | |
75 | . ds #[ \f1 | |
76 | . ds #] \fP | |
77 | .\} | |
78 | .if t \{\ | |
79 | . ds #H ((1u-(\\\\n(.fu%2u))*.13m) | |
80 | . ds #V .6m | |
81 | . ds #F 0 | |
82 | . ds #[ \& | |
83 | . ds #] \& | |
84 | .\} | |
85 | . \" simple accents for nroff and troff | |
86 | .if n \{\ | |
87 | . ds ' \& | |
88 | . ds ` \& | |
89 | . ds ^ \& | |
90 | . ds , \& | |
91 | . ds ~ ~ | |
92 | . ds / | |
93 | .\} | |
94 | .if t \{\ | |
95 | . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" | |
96 | . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' | |
97 | . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' | |
98 | . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' | |
99 | . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' | |
100 | . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' | |
101 | .\} | |
102 | . \" troff and (daisy-wheel) nroff accents | |
103 | .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' | |
104 | .ds 8 \h'\*(#H'\(*b\h'-\*(#H' | |
105 | .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] | |
106 | .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' | |
107 | .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' | |
108 | .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] | |
109 | .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] | |
110 | .ds ae a\h'-(\w'a'u*4/10)'e | |
111 | .ds Ae A\h'-(\w'A'u*4/10)'E | |
112 | . \" corrections for vroff | |
113 | .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' | |
114 | .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' | |
115 | . \" for low resolution devices (crt and lpr) | |
116 | .if \n(.H>23 .if \n(.V>19 \ | |
117 | \{\ | |
118 | . ds : e | |
119 | . ds 8 ss | |
120 | . ds o a | |
121 | . ds d- d\h'-1'\(ga | |
122 | . ds D- D\h'-1'\(hy | |
123 | . ds th \o'bp' | |
124 | . ds Th \o'LP' | |
125 | . ds ae ae | |
126 | . ds Ae AE | |
127 | .\} | |
128 | .rm #[ #] #H #V #F C | |
129 | .\" ======================================================================== | |
130 | .\" | |
131 | .IX Title "Test::Builder 3" | |
132 | .TH Test::Builder 3 "2001-09-21" "perl v5.8.8" "Perl Programmers Reference Guide" | |
133 | .SH "NAME" | |
134 | Test::Builder \- Backend for building test libraries | |
135 | .SH "SYNOPSIS" | |
136 | .IX Header "SYNOPSIS" | |
137 | .Vb 5 | |
138 | \& package My::Test::Module; | |
139 | \& use Test::Builder; | |
140 | \& require Exporter; | |
141 | \& @ISA = qw(Exporter); | |
142 | \& @EXPORT = qw(ok); | |
143 | .Ve | |
144 | .PP | |
145 | .Vb 2 | |
146 | \& my $Test = Test::Builder->new; | |
147 | \& $Test->output('my_logfile'); | |
148 | .Ve | |
149 | .PP | |
150 | .Vb 3 | |
151 | \& sub import { | |
152 | \& my($self) = shift; | |
153 | \& my $pack = caller; | |
154 | .Ve | |
155 | .PP | |
156 | .Vb 2 | |
157 | \& $Test->exported_to($pack); | |
158 | \& $Test->plan(@_); | |
159 | .Ve | |
160 | .PP | |
161 | .Vb 2 | |
162 | \& $self->export_to_level(1, $self, 'ok'); | |
163 | \& } | |
164 | .Ve | |
165 | .PP | |
166 | .Vb 2 | |
167 | \& sub ok { | |
168 | \& my($test, $name) = @_; | |
169 | .Ve | |
170 | .PP | |
171 | .Vb 2 | |
172 | \& $Test->ok($test, $name); | |
173 | \& } | |
174 | .Ve | |
175 | .SH "DESCRIPTION" | |
176 | .IX Header "DESCRIPTION" | |
177 | Test::Simple and Test::More have proven to be popular testing modules, | |
178 | but they're not always flexible enough. Test::Builder provides the a | |
179 | building block upon which to write your own test libraries \fIwhich can | |
180 | work together\fR. | |
181 | .Sh "Construction" | |
182 | .IX Subsection "Construction" | |
183 | .IP "\fBnew\fR" 4 | |
184 | .IX Item "new" | |
185 | .Vb 1 | |
186 | \& my $Test = Test::Builder->new; | |
187 | .Ve | |
188 | .Sp | |
189 | Returns a Test::Builder object representing the current state of the | |
190 | test. | |
191 | .Sp | |
192 | Since you only run one test per program \f(CW\*(C`new\*(C'\fR always returns the same | |
193 | Test::Builder object. No matter how many times you call \fInew()\fR, you're | |
194 | getting the same object. This is called a singleton. This is done so that | |
195 | multiple modules share such global information as the test counter and | |
196 | where test output is going. | |
197 | .Sp | |
198 | If you want a completely new Test::Builder object different from the | |
199 | singleton, use \f(CW\*(C`create\*(C'\fR. | |
200 | .IP "\fBcreate\fR" 4 | |
201 | .IX Item "create" | |
202 | .Vb 1 | |
203 | \& my $Test = Test::Builder->create; | |
204 | .Ve | |
205 | .Sp | |
206 | Ok, so there can be more than one Test::Builder object and this is how | |
207 | you get it. You might use this instead of \f(CW\*(C`new()\*(C'\fR if you're testing | |
208 | a Test::Builder based module, but otherwise you probably want \f(CW\*(C`new\*(C'\fR. | |
209 | .Sp | |
210 | \&\fB\s-1NOTE\s0\fR: the implementation is not complete. \f(CW\*(C`level\*(C'\fR, for example, is | |
211 | still shared amongst \fBall\fR Test::Builder objects, even ones created using | |
212 | this method. Also, the method name may change in the future. | |
213 | .IP "\fBreset\fR" 4 | |
214 | .IX Item "reset" | |
215 | .Vb 1 | |
216 | \& $Test->reset; | |
217 | .Ve | |
218 | .Sp | |
219 | Reinitializes the Test::Builder singleton to its original state. | |
220 | Mostly useful for tests run in persistent environments where the same | |
221 | test might be run multiple times in the same process. | |
222 | .Sh "Setting up tests" | |
223 | .IX Subsection "Setting up tests" | |
224 | These methods are for setting up tests and declaring how many there | |
225 | are. You usually only want to call one of these methods. | |
226 | .IP "\fBexported_to\fR" 4 | |
227 | .IX Item "exported_to" | |
228 | .Vb 2 | |
229 | \& my $pack = $Test->exported_to; | |
230 | \& $Test->exported_to($pack); | |
231 | .Ve | |
232 | .Sp | |
233 | Tells Test::Builder what package you exported your functions to. | |
234 | This is important for getting \s-1TODO\s0 tests right. | |
235 | .IP "\fBplan\fR" 4 | |
236 | .IX Item "plan" | |
237 | .Vb 3 | |
238 | \& $Test->plan('no_plan'); | |
239 | \& $Test->plan( skip_all => $reason ); | |
240 | \& $Test->plan( tests => $num_tests ); | |
241 | .Ve | |
242 | .Sp | |
243 | A convenient way to set up your tests. Call this and Test::Builder | |
244 | will print the appropriate headers and take the appropriate actions. | |
245 | .Sp | |
246 | If you call \fIplan()\fR, don't call any of the other methods below. | |
247 | .IP "\fBexpected_tests\fR" 4 | |
248 | .IX Item "expected_tests" | |
249 | .Vb 2 | |
250 | \& my $max = $Test->expected_tests; | |
251 | \& $Test->expected_tests($max); | |
252 | .Ve | |
253 | .Sp | |
254 | Gets/sets the # of tests we expect this test to run and prints out | |
255 | the appropriate headers. | |
256 | .IP "\fBno_plan\fR" 4 | |
257 | .IX Item "no_plan" | |
258 | .Vb 1 | |
259 | \& $Test->no_plan; | |
260 | .Ve | |
261 | .Sp | |
262 | Declares that this test will run an indeterminate # of tests. | |
263 | .IP "\fBhas_plan\fR" 4 | |
264 | .IX Item "has_plan" | |
265 | .Vb 1 | |
266 | \& $plan = $Test->has_plan | |
267 | .Ve | |
268 | .Sp | |
269 | Find out whether a plan has been defined. \f(CW$plan\fR is either \f(CW\*(C`undef\*(C'\fR (no plan has been set), \f(CW\*(C`no_plan\*(C'\fR (indeterminate # of tests) or an integer (the number of expected tests). | |
270 | .IP "\fBskip_all\fR" 4 | |
271 | .IX Item "skip_all" | |
272 | .Vb 2 | |
273 | \& $Test->skip_all; | |
274 | \& $Test->skip_all($reason); | |
275 | .Ve | |
276 | .Sp | |
277 | Skips all the tests, using the given \f(CW$reason\fR. Exits immediately with 0. | |
278 | .Sh "Running tests" | |
279 | .IX Subsection "Running tests" | |
280 | These actually run the tests, analogous to the functions in | |
281 | Test::More. | |
282 | .PP | |
283 | $name is always optional. | |
284 | .IP "\fBok\fR" 4 | |
285 | .IX Item "ok" | |
286 | .Vb 1 | |
287 | \& $Test->ok($test, $name); | |
288 | .Ve | |
289 | .Sp | |
290 | Your basic test. Pass if \f(CW$test\fR is true, fail if \f(CW$test\fR is false. Just | |
291 | like Test::Simple's \fIok()\fR. | |
292 | .IP "\fBis_eq\fR" 4 | |
293 | .IX Item "is_eq" | |
294 | .Vb 1 | |
295 | \& $Test->is_eq($got, $expected, $name); | |
296 | .Ve | |
297 | .Sp | |
298 | Like Test::More's \fIis()\fR. Checks if \f(CW$got\fR eq \f(CW$expected\fR. This is the | |
299 | string version. | |
300 | .IP "\fBis_num\fR" 4 | |
301 | .IX Item "is_num" | |
302 | .Vb 1 | |
303 | \& $Test->is_num($got, $expected, $name); | |
304 | .Ve | |
305 | .Sp | |
306 | Like Test::More's \fIis()\fR. Checks if \f(CW$got\fR == \f(CW$expected\fR. This is the | |
307 | numeric version. | |
308 | .IP "\fBisnt_eq\fR" 4 | |
309 | .IX Item "isnt_eq" | |
310 | .Vb 1 | |
311 | \& $Test->isnt_eq($got, $dont_expect, $name); | |
312 | .Ve | |
313 | .Sp | |
314 | Like Test::More's \fIisnt()\fR. Checks if \f(CW$got\fR ne \f(CW$dont_expect\fR. This is | |
315 | the string version. | |
316 | .IP "\fBisnt_num\fR" 4 | |
317 | .IX Item "isnt_num" | |
318 | .Vb 1 | |
319 | \& $Test->is_num($got, $dont_expect, $name); | |
320 | .Ve | |
321 | .Sp | |
322 | Like Test::More's \fIisnt()\fR. Checks if \f(CW$got\fR ne \f(CW$dont_expect\fR. This is | |
323 | the numeric version. | |
324 | .IP "\fBlike\fR" 4 | |
325 | .IX Item "like" | |
326 | .Vb 2 | |
327 | \& $Test->like($this, qr/$regex/, $name); | |
328 | \& $Test->like($this, '/$regex/', $name); | |
329 | .Ve | |
330 | .Sp | |
331 | Like Test::More's \fIlike()\fR. Checks if \f(CW$this\fR matches the given \f(CW$regex\fR. | |
332 | .Sp | |
333 | You'll want to avoid qr// if you want your tests to work before 5.005. | |
334 | .IP "\fBunlike\fR" 4 | |
335 | .IX Item "unlike" | |
336 | .Vb 2 | |
337 | \& $Test->unlike($this, qr/$regex/, $name); | |
338 | \& $Test->unlike($this, '/$regex/', $name); | |
339 | .Ve | |
340 | .Sp | |
341 | Like Test::More's \fIunlike()\fR. Checks if \f(CW$this\fR \fBdoes not match\fR the | |
342 | given \f(CW$regex\fR. | |
343 | .IP "\fBmaybe_regex\fR" 4 | |
344 | .IX Item "maybe_regex" | |
345 | .Vb 2 | |
346 | \& $Test->maybe_regex(qr/$regex/); | |
347 | \& $Test->maybe_regex('/$regex/'); | |
348 | .Ve | |
349 | .Sp | |
350 | Convenience method for building testing functions that take regular | |
351 | expressions as arguments, but need to work before perl 5.005. | |
352 | .Sp | |
353 | Takes a quoted regular expression produced by qr//, or a string | |
354 | representing a regular expression. | |
355 | .Sp | |
356 | Returns a Perl value which may be used instead of the corresponding | |
357 | regular expression, or undef if it's argument is not recognised. | |
358 | .Sp | |
359 | For example, a version of \fIlike()\fR, sans the useful diagnostic messages, | |
360 | could be written as: | |
361 | .Sp | |
362 | .Vb 7 | |
363 | \& sub laconic_like { | |
364 | \& my ($self, $this, $regex, $name) = @_; | |
365 | \& my $usable_regex = $self->maybe_regex($regex); | |
366 | \& die "expecting regex, found '$regex'\en" | |
367 | \& unless $usable_regex; | |
368 | \& $self->ok($this =~ m/$usable_regex/, $name); | |
369 | \& } | |
370 | .Ve | |
371 | .IP "\fBcmp_ok\fR" 4 | |
372 | .IX Item "cmp_ok" | |
373 | .Vb 1 | |
374 | \& $Test->cmp_ok($this, $type, $that, $name); | |
375 | .Ve | |
376 | .Sp | |
377 | Works just like Test::More's \fIcmp_ok()\fR. | |
378 | .Sp | |
379 | .Vb 1 | |
380 | \& $Test->cmp_ok($big_num, '!=', $other_big_num); | |
381 | .Ve | |
382 | .IP "\fB\s-1BAIL_OUT\s0\fR" 4 | |
383 | .IX Item "BAIL_OUT" | |
384 | .Vb 1 | |
385 | \& $Test->BAIL_OUT($reason); | |
386 | .Ve | |
387 | .Sp | |
388 | Indicates to the Test::Harness that things are going so badly all | |
389 | testing should terminate. This includes running any additional test | |
390 | scripts. | |
391 | .Sp | |
392 | It will exit with 255. | |
393 | .IP "\fBskip\fR" 4 | |
394 | .IX Item "skip" | |
395 | .Vb 2 | |
396 | \& $Test->skip; | |
397 | \& $Test->skip($why); | |
398 | .Ve | |
399 | .Sp | |
400 | Skips the current test, reporting \f(CW$why\fR. | |
401 | .IP "\fBtodo_skip\fR" 4 | |
402 | .IX Item "todo_skip" | |
403 | .Vb 2 | |
404 | \& $Test->todo_skip; | |
405 | \& $Test->todo_skip($why); | |
406 | .Ve | |
407 | .Sp | |
408 | Like \fIskip()\fR, only it will declare the test as failing and \s-1TODO\s0. Similar | |
409 | to | |
410 | .Sp | |
411 | .Vb 1 | |
412 | \& print "not ok $tnum # TODO $why\en"; | |
413 | .Ve | |
414 | .Sh "Test style" | |
415 | .IX Subsection "Test style" | |
416 | .IP "\fBlevel\fR" 4 | |
417 | .IX Item "level" | |
418 | .Vb 1 | |
419 | \& $Test->level($how_high); | |
420 | .Ve | |
421 | .Sp | |
422 | How far up the call stack should \f(CW$Test\fR look when reporting where the | |
423 | test failed. | |
424 | .Sp | |
425 | Defaults to 1. | |
426 | .Sp | |
427 | Setting \f(CW$Test::Builder::Level\fR overrides. This is typically useful | |
428 | localized: | |
429 | .Sp | |
430 | .Vb 4 | |
431 | \& { | |
432 | \& local $Test::Builder::Level = 2; | |
433 | \& $Test->ok($test); | |
434 | \& } | |
435 | .Ve | |
436 | .IP "\fBuse_numbers\fR" 4 | |
437 | .IX Item "use_numbers" | |
438 | .Vb 1 | |
439 | \& $Test->use_numbers($on_or_off); | |
440 | .Ve | |
441 | .Sp | |
442 | Whether or not the test should output numbers. That is, this if true: | |
443 | .Sp | |
444 | .Vb 3 | |
445 | \& ok 1 | |
446 | \& ok 2 | |
447 | \& ok 3 | |
448 | .Ve | |
449 | .Sp | |
450 | or this if false | |
451 | .Sp | |
452 | .Vb 3 | |
453 | \& ok | |
454 | \& ok | |
455 | \& ok | |
456 | .Ve | |
457 | .Sp | |
458 | Most useful when you can't depend on the test output order, such as | |
459 | when threads or forking is involved. | |
460 | .Sp | |
461 | Test::Harness will accept either, but avoid mixing the two styles. | |
462 | .Sp | |
463 | Defaults to on. | |
464 | .IP "\fBno_diag\fR" 4 | |
465 | .IX Item "no_diag" | |
466 | .Vb 1 | |
467 | \& $Test->no_diag($no_diag); | |
468 | .Ve | |
469 | .Sp | |
470 | If set true no diagnostics will be printed. This includes calls to | |
471 | \&\fIdiag()\fR. | |
472 | .IP "\fBno_ending\fR" 4 | |
473 | .IX Item "no_ending" | |
474 | .Vb 1 | |
475 | \& $Test->no_ending($no_ending); | |
476 | .Ve | |
477 | .Sp | |
478 | Normally, Test::Builder does some extra diagnostics when the test | |
479 | ends. It also changes the exit code as described below. | |
480 | .Sp | |
481 | If this is true, none of that will be done. | |
482 | .IP "\fBno_header\fR" 4 | |
483 | .IX Item "no_header" | |
484 | .Vb 1 | |
485 | \& $Test->no_header($no_header); | |
486 | .Ve | |
487 | .Sp | |
488 | If set to true, no \*(L"1..N\*(R" header will be printed. | |
489 | .Sh "Output" | |
490 | .IX Subsection "Output" | |
491 | Controlling where the test output goes. | |
492 | .PP | |
493 | It's ok for your test to change where \s-1STDOUT\s0 and \s-1STDERR\s0 point to, | |
494 | Test::Builder's default output settings will not be affected. | |
495 | .IP "\fBdiag\fR" 4 | |
496 | .IX Item "diag" | |
497 | .Vb 1 | |
498 | \& $Test->diag(@msgs); | |
499 | .Ve | |
500 | .Sp | |
501 | Prints out the given \f(CW@msgs\fR. Like \f(CW\*(C`print\*(C'\fR, arguments are simply | |
502 | appended together. | |
503 | .Sp | |
504 | Normally, it uses the \fIfailure_output()\fR handle, but if this is for a | |
505 | \&\s-1TODO\s0 test, the \fItodo_output()\fR handle is used. | |
506 | .Sp | |
507 | Output will be indented and marked with a # so as not to interfere | |
508 | with test output. A newline will be put on the end if there isn't one | |
509 | already. | |
510 | .Sp | |
511 | We encourage using this rather than calling print directly. | |
512 | .Sp | |
513 | Returns false. Why? Because \fIdiag()\fR is often used in conjunction with | |
514 | a failing test (\f(CW\*(C`ok() || diag()\*(C'\fR) it \*(L"passes through\*(R" the failure. | |
515 | .Sp | |
516 | .Vb 1 | |
517 | \& return ok(...) || diag(...); | |
518 | .Ve | |
519 | .IP "\fB_print_diag\fR" 4 | |
520 | .IX Item "_print_diag" | |
521 | .Vb 1 | |
522 | \& $Test->_print_diag(@msg); | |
523 | .Ve | |
524 | .Sp | |
525 | Like _print, but prints to the current diagnostic filehandle. | |
526 | .IP "\fBoutput\fR" 4 | |
527 | .IX Item "output" | |
528 | .Vb 2 | |
529 | \& $Test->output($fh); | |
530 | \& $Test->output($file); | |
531 | .Ve | |
532 | .Sp | |
533 | Where normal \*(L"ok/not ok\*(R" test output should go. | |
534 | .Sp | |
535 | Defaults to \s-1STDOUT\s0. | |
536 | .IP "\fBfailure_output\fR" 4 | |
537 | .IX Item "failure_output" | |
538 | .Vb 2 | |
539 | \& $Test->failure_output($fh); | |
540 | \& $Test->failure_output($file); | |
541 | .Ve | |
542 | .Sp | |
543 | Where diagnostic output on test failures and \fIdiag()\fR should go. | |
544 | .Sp | |
545 | Defaults to \s-1STDERR\s0. | |
546 | .IP "\fBtodo_output\fR" 4 | |
547 | .IX Item "todo_output" | |
548 | .Vb 2 | |
549 | \& $Test->todo_output($fh); | |
550 | \& $Test->todo_output($file); | |
551 | .Ve | |
552 | .Sp | |
553 | Where diagnostics about todo test failures and \fIdiag()\fR should go. | |
554 | .Sp | |
555 | Defaults to \s-1STDOUT\s0. | |
556 | .Sh "Test Status and Info" | |
557 | .IX Subsection "Test Status and Info" | |
558 | .IP "\fBcurrent_test\fR" 4 | |
559 | .IX Item "current_test" | |
560 | .Vb 2 | |
561 | \& my $curr_test = $Test->current_test; | |
562 | \& $Test->current_test($num); | |
563 | .Ve | |
564 | .Sp | |
565 | Gets/sets the current test number we're on. You usually shouldn't | |
566 | have to set this. | |
567 | .Sp | |
568 | If set forward, the details of the missing tests are filled in as 'unknown'. | |
569 | if set backward, the details of the intervening tests are deleted. You | |
570 | can erase history if you really want to. | |
571 | .IP "\fBsummary\fR" 4 | |
572 | .IX Item "summary" | |
573 | .Vb 1 | |
574 | \& my @tests = $Test->summary; | |
575 | .Ve | |
576 | .Sp | |
577 | A simple summary of the tests so far. True for pass, false for fail. | |
578 | This is a logical pass/fail, so todos are passes. | |
579 | .Sp | |
580 | Of course, test #1 is \f(CW$tests\fR[0], etc... | |
581 | .IP "\fBdetails\fR" 4 | |
582 | .IX Item "details" | |
583 | .Vb 1 | |
584 | \& my @tests = $Test->details; | |
585 | .Ve | |
586 | .Sp | |
587 | Like \fIsummary()\fR, but with a lot more detail. | |
588 | .Sp | |
589 | .Vb 7 | |
590 | \& $tests[$test_num - 1] = | |
591 | \& { 'ok' => is the test considered a pass? | |
592 | \& actual_ok => did it literally say 'ok'? | |
593 | \& name => name of the test (if any) | |
594 | \& type => type of test (if any, see below). | |
595 | \& reason => reason for the above (if any) | |
596 | \& }; | |
597 | .Ve | |
598 | .Sp | |
599 | \&'ok' is true if Test::Harness will consider the test to be a pass. | |
600 | .Sp | |
601 | \&'actual_ok' is a reflection of whether or not the test literally | |
602 | printed 'ok' or 'not ok'. This is for examining the result of 'todo' | |
603 | tests. | |
604 | .Sp | |
605 | \&'name' is the name of the test. | |
606 | .Sp | |
607 | \&'type' indicates if it was a special test. Normal tests have a type | |
608 | of ''. Type can be one of the following: | |
609 | .Sp | |
610 | .Vb 4 | |
611 | \& skip see skip() | |
612 | \& todo see todo() | |
613 | \& todo_skip see todo_skip() | |
614 | \& unknown see below | |
615 | .Ve | |
616 | .Sp | |
617 | Sometimes the Test::Builder test counter is incremented without it | |
618 | printing any test output, for example, when \fIcurrent_test()\fR is changed. | |
619 | In these cases, Test::Builder doesn't know the result of the test, so | |
620 | it's type is 'unkown'. These details for these tests are filled in. | |
621 | They are considered ok, but the name and actual_ok is left undef. | |
622 | .Sp | |
623 | For example \*(L"not ok 23 \- hole count # \s-1TODO\s0 insufficient donuts\*(R" would | |
624 | result in this structure: | |
625 | .Sp | |
626 | .Vb 7 | |
627 | \& $tests[22] = # 23 - 1, since arrays start from 0. | |
628 | \& { ok => 1, # logically, the test passed since it's todo | |
629 | \& actual_ok => 0, # in absolute terms, it failed | |
630 | \& name => 'hole count', | |
631 | \& type => 'todo', | |
632 | \& reason => 'insufficient donuts' | |
633 | \& }; | |
634 | .Ve | |
635 | .IP "\fBtodo\fR" 4 | |
636 | .IX Item "todo" | |
637 | .Vb 2 | |
638 | \& my $todo_reason = $Test->todo; | |
639 | \& my $todo_reason = $Test->todo($pack); | |
640 | .Ve | |
641 | .Sp | |
642 | \&\fItodo()\fR looks for a \f(CW$TODO\fR variable in your tests. If set, all tests | |
643 | will be considered 'todo' (see Test::More and Test::Harness for | |
644 | details). Returns the reason (ie. the value of \f(CW$TODO\fR) if running as | |
645 | todo tests, false otherwise. | |
646 | .Sp | |
647 | \&\fItodo()\fR is about finding the right package to look for \f(CW$TODO\fR in. It | |
648 | uses the \fIexported_to()\fR package to find it. If that's not set, it's | |
649 | pretty good at guessing the right package to look at based on \f(CW$Level\fR. | |
650 | .Sp | |
651 | Sometimes there is some confusion about where \fItodo()\fR should be looking | |
652 | for the \f(CW$TODO\fR variable. If you want to be sure, tell it explicitly | |
653 | what \f(CW$pack\fR to use. | |
654 | .IP "\fBcaller\fR" 4 | |
655 | .IX Item "caller" | |
656 | .Vb 3 | |
657 | \& my $package = $Test->caller; | |
658 | \& my($pack, $file, $line) = $Test->caller; | |
659 | \& my($pack, $file, $line) = $Test->caller($height); | |
660 | .Ve | |
661 | .Sp | |
662 | Like the normal \fIcaller()\fR, except it reports according to your \fIlevel()\fR. | |
663 | .SH "EXIT CODES" | |
664 | .IX Header "EXIT CODES" | |
665 | If all your tests passed, Test::Builder will exit with zero (which is | |
666 | normal). If anything failed it will exit with how many failed. If | |
667 | you run less (or more) tests than you planned, the missing (or extras) | |
668 | will be considered failures. If no tests were ever run Test::Builder | |
669 | will throw a warning and exit with 255. If the test died, even after | |
670 | having successfully completed all its tests, it will still be | |
671 | considered a failure and will exit with 255. | |
672 | .PP | |
673 | So the exit codes are... | |
674 | .PP | |
675 | .Vb 3 | |
676 | \& 0 all tests successful | |
677 | \& 255 test died or all passed but wrong # of tests run | |
678 | \& any other number how many failed (including missing or extras) | |
679 | .Ve | |
680 | .PP | |
681 | If you fail more than 254 tests, it will be reported as 254. | |
682 | .SH "THREADS" | |
683 | .IX Header "THREADS" | |
684 | In perl 5.8.0 and later, Test::Builder is thread\-safe. The test | |
685 | number is shared amongst all threads. This means if one thread sets | |
686 | the test number using \fIcurrent_test()\fR they will all be effected. | |
687 | .PP | |
688 | Test::Builder is only thread-aware if threads.pm is loaded \fIbefore\fR | |
689 | Test::Builder. | |
690 | .SH "EXAMPLES" | |
691 | .IX Header "EXAMPLES" | |
692 | \&\s-1CPAN\s0 can provide the best examples. Test::Simple, Test::More, | |
693 | Test::Exception and Test::Differences all use Test::Builder. | |
694 | .SH "SEE ALSO" | |
695 | .IX Header "SEE ALSO" | |
696 | Test::Simple, Test::More, Test::Harness | |
697 | .SH "AUTHORS" | |
698 | .IX Header "AUTHORS" | |
699 | Original code by chromatic, maintained by Michael G Schwern | |
700 | <schwern@pobox.com> | |
701 | .SH "COPYRIGHT" | |
702 | .IX Header "COPYRIGHT" | |
703 | Copyright 2002, 2004 by chromatic <chromatic@wgz.org> and | |
704 | Michael G Schwern <schwern@pobox.com>. | |
705 | .PP | |
706 | This program is free software; you can redistribute it and/or | |
707 | modify it under the same terms as Perl itself. | |
708 | .PP | |
709 | See \fIhttp://www.perl.com/perl/misc/Artistic.html\fR |