Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / man / man3 / Test::More.3
CommitLineData
86530b38
AT
1.\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13
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::More 3"
132.TH Test::More 3 "2002-06-01" "perl v5.8.0" "Perl Programmers Reference Guide"
133.SH "NAME"
134Test::More \- yet another framework for writing test scripts
135.SH "SYNOPSIS"
136.IX Header "SYNOPSIS"
137.Vb 5
138\& use Test::More tests => $Num_Tests;
139\& # or
140\& use Test::More qw(no_plan);
141\& # or
142\& use Test::More skip_all => $reason;
143.Ve
144.PP
145.Vb 2
146\& BEGIN { use_ok( 'Some::Module' ); }
147\& require_ok( 'Some::Module' );
148.Ve
149.PP
150.Vb 2
151\& # Various ways to say "ok"
152\& ok($this eq $that, $test_name);
153.Ve
154.PP
155.Vb 2
156\& is ($this, $that, $test_name);
157\& isnt($this, $that, $test_name);
158.Ve
159.PP
160.Vb 2
161\& # Rather than print STDERR "# here's what went wrong\en"
162\& diag("here's what went wrong");
163.Ve
164.PP
165.Vb 2
166\& like ($this, qr/that/, $test_name);
167\& unlike($this, qr/that/, $test_name);
168.Ve
169.PP
170.Vb 1
171\& cmp_ok($this, '==', $that, $test_name);
172.Ve
173.PP
174.Vb 1
175\& is_deeply($complex_structure1, $complex_structure2, $test_name);
176.Ve
177.PP
178.Vb 2
179\& SKIP: {
180\& skip $why, $how_many unless $have_some_feature;
181.Ve
182.PP
183.Vb 3
184\& ok( foo(), $test_name );
185\& is( foo(42), 23, $test_name );
186\& };
187.Ve
188.PP
189.Vb 2
190\& TODO: {
191\& local $TODO = $why;
192.Ve
193.PP
194.Vb 3
195\& ok( foo(), $test_name );
196\& is( foo(42), 23, $test_name );
197\& };
198.Ve
199.PP
200.Vb 2
201\& can_ok($module, @methods);
202\& isa_ok($object, $class);
203.Ve
204.PP
205.Vb 2
206\& pass($test_name);
207\& fail($test_name);
208.Ve
209.PP
210.Vb 4
211\& # Utility comparison functions.
212\& eq_array(\e@this, \e@that);
213\& eq_hash(\e%this, \e%that);
214\& eq_set(\e@this, \e@that);
215.Ve
216.PP
217.Vb 2
218\& # UNIMPLEMENTED!!!
219\& my @status = Test::More::status;
220.Ve
221.PP
222.Vb 2
223\& # UNIMPLEMENTED!!!
224\& BAIL_OUT($why);
225.Ve
226.SH "DESCRIPTION"
227.IX Header "DESCRIPTION"
228\&\fB\s-1STOP\s0!\fR If you're just getting started writing tests, have a look at
229Test::Simple first. This is a drop in replacement for Test::Simple
230which you can switch to once you get the hang of basic testing.
231.PP
232The purpose of this module is to provide a wide range of testing
233utilities. Various ways to say \*(L"ok\*(R" with better diagnostics,
234facilities to skip tests, test future features and compare complicated
235data structures. While you can do almost anything with a simple
236\&\f(CW\*(C`ok()\*(C'\fR function, it doesn't provide good diagnostic output.
237.Sh "I love it when a plan comes together"
238.IX Subsection "I love it when a plan comes together"
239Before anything else, you need a testing plan. This basically declares
240how many tests your script is going to run to protect against premature
241failure.
242.PP
243The preferred way to do this is to declare a plan when you \f(CW\*(C`use Test::More\*(C'\fR.
244.PP
245.Vb 1
246\& use Test::More tests => $Num_Tests;
247.Ve
248.PP
249There are rare cases when you will not know beforehand how many tests
250your script is going to run. In this case, you can declare that you
251have no plan. (Try to avoid using this as it weakens your test.)
252.PP
253.Vb 1
254\& use Test::More qw(no_plan);
255.Ve
256.PP
257In some cases, you'll want to completely skip an entire testing script.
258.PP
259.Vb 1
260\& use Test::More skip_all => $skip_reason;
261.Ve
262.PP
263Your script will declare a skip with the reason why you skipped and
264exit immediately with a zero (success). See Test::Harness for
265details.
266.PP
267If you want to control what functions Test::More will export, you
268have to use the 'import' option. For example, to import everything
269but 'fail', you'd do:
270.PP
271.Vb 1
272\& use Test::More tests => 23, import => ['!fail'];
273.Ve
274.PP
275Alternatively, you can use the \fIplan()\fR function. Useful for when you
276have to calculate the number of tests.
277.PP
278.Vb 2
279\& use Test::More;
280\& plan tests => keys %Stuff * 3;
281.Ve
282.PP
283or for deciding between running the tests at all:
284.PP
285.Vb 7
286\& use Test::More;
287\& if( $^O eq 'MacOS' ) {
288\& plan skip_all => 'Test irrelevant on MacOS';
289\& }
290\& else {
291\& plan tests => 42;
292\& }
293.Ve
294.Sh "Test names"
295.IX Subsection "Test names"
296By convention, each test is assigned a number in order. This is
297largely done automatically for you. However, it's often very useful to
298assign a name to each test. Which would you rather see:
299.PP
300.Vb 3
301\& ok 4
302\& not ok 5
303\& ok 6
304.Ve
305.PP
306or
307.PP
308.Vb 3
309\& ok 4 - basic multi-variable
310\& not ok 5 - simple exponential
311\& ok 6 - force == mass * acceleration
312.Ve
313.PP
314The later gives you some idea of what failed. It also makes it easier
315to find the test in your script, simply search for \*(L"simple
316exponential\*(R".
317.PP
318All test functions take a name argument. It's optional, but highly
319suggested that you use it.
320.Sh "I'm ok, you're not ok."
321.IX Subsection "I'm ok, you're not ok."
322The basic purpose of this module is to print out either \*(L"ok #\*(R" or \*(L"not
323ok #\*(R" depending on if a given test succeeded or failed. Everything
324else is just gravy.
325.PP
326All of the following print \*(L"ok\*(R" or \*(L"not ok\*(R" depending on if the test
327succeeded or failed. They all also return true or false,
328respectively.
329.IP "\fBok\fR" 4
330.IX Item "ok"
331.Vb 1
332\& ok($this eq $that, $test_name);
333.Ve
334.Sp
335This simply evaluates any expression (\f(CW\*(C`$this eq $that\*(C'\fR is just a
336simple example) and uses that to determine if the test succeeded or
337failed. A true expression passes, a false one fails. Very simple.
338.Sp
339For example:
340.Sp
341.Vb 4
342\& ok( $exp{9} == 81, 'simple exponential' );
343\& ok( Film->can('db_Main'), 'set_db()' );
344\& ok( $p->tests == 4, 'saw tests' );
345\& ok( !grep !defined $_, @items, 'items populated' );
346.Ve
347.Sp
348(Mnemonic: \*(L"This is ok.\*(R")
349.Sp
350$test_name is a very short description of the test that will be printed
351out. It makes it very easy to find a test in your script when it fails
352and gives others an idea of your intentions. \f(CW$test_name\fR is optional,
353but we \fBvery\fR strongly encourage its use.
354.Sp
355Should an \fIok()\fR fail, it will produce some diagnostics:
356.Sp
357.Vb 2
358\& not ok 18 - sufficient mucus
359\& # Failed test 18 (foo.t at line 42)
360.Ve
361.Sp
362This is actually Test::Simple's \fIok()\fR routine.
363.IP "\fBis\fR" 4
364.IX Item "is"
365.PD 0
366.IP "\fBisnt\fR" 4
367.IX Item "isnt"
368.PD
369.Vb 2
370\& is ( $this, $that, $test_name );
371\& isnt( $this, $that, $test_name );
372.Ve
373.Sp
374Similar to \fIok()\fR, \fIis()\fR and \fIisnt()\fR compare their two arguments
375with \f(CW\*(C`eq\*(C'\fR and \f(CW\*(C`ne\*(C'\fR respectively and use the result of that to
376determine if the test succeeded or failed. So these:
377.Sp
378.Vb 2
379\& # Is the ultimate answer 42?
380\& is( ultimate_answer(), 42, "Meaning of Life" );
381.Ve
382.Sp
383.Vb 2
384\& # $foo isn't empty
385\& isnt( $foo, '', "Got some foo" );
386.Ve
387.Sp
388are similar to these:
389.Sp
390.Vb 2
391\& ok( ultimate_answer() eq 42, "Meaning of Life" );
392\& ok( $foo ne '', "Got some foo" );
393.Ve
394.Sp
395(Mnemonic: \*(L"This is that.\*(R" \*(L"This isn't that.\*(R")
396.Sp
397So why use these? They produce better diagnostics on failure. \fIok()\fR
398cannot know what you are testing for (beyond the name), but \fIis()\fR and
399\&\fIisnt()\fR know what the test was and why it failed. For example this
400test:
401.Sp
402.Vb 2
403\& my $foo = 'waffle'; my $bar = 'yarblokos';
404\& is( $foo, $bar, 'Is foo the same as bar?' );
405.Ve
406.Sp
407Will produce something like this:
408.Sp
409.Vb 4
410\& not ok 17 - Is foo the same as bar?
411\& # Failed test 1 (foo.t at line 139)
412\& # got: 'waffle'
413\& # expected: 'yarblokos'
414.Ve
415.Sp
416So you can figure out what went wrong without rerunning the test.
417.Sp
418You are encouraged to use \fIis()\fR and \fIisnt()\fR over \fIok()\fR where possible,
419however do not be tempted to use them to find out if something is
420true or false!
421.Sp
422.Vb 2
423\& # XXX BAD! $pope->isa('Catholic') eq 1
424\& is( $pope->isa('Catholic'), 1, 'Is the Pope Catholic?' );
425.Ve
426.Sp
427This does not check if \f(CW\*(C`$pope\-\*(C'\fRisa('Catholic')> is true, it checks if
428it returns 1. Very different. Similar caveats exist for false and 0.
429In these cases, use \fIok()\fR.
430.Sp
431.Vb 1
432\& ok( $pope->isa('Catholic') ), 'Is the Pope Catholic?' );
433.Ve
434.Sp
435For those grammatical pedants out there, there's an \f(CW\*(C`isn't()\*(C'\fR
436function which is an alias of \fIisnt()\fR.
437.IP "\fBlike\fR" 4
438.IX Item "like"
439.Vb 1
440\& like( $this, qr/that/, $test_name );
441.Ve
442.Sp
443Similar to \fIok()\fR, \fIlike()\fR matches \f(CW$this\fR against the regex \f(CW\*(C`qr/that/\*(C'\fR.
444.Sp
445So this:
446.Sp
447.Vb 1
448\& like($this, qr/that/, 'this is like that');
449.Ve
450.Sp
451is similar to:
452.Sp
453.Vb 1
454\& ok( $this =~ /that/, 'this is like that');
455.Ve
456.Sp
457(Mnemonic \*(L"This is like that\*(R".)
458.Sp
459The second argument is a regular expression. It may be given as a
460regex reference (i.e. \f(CW\*(C`qr//\*(C'\fR) or (for better compatibility with older
461perls) as a string that looks like a regex (alternative delimiters are
462currently not supported):
463.Sp
464.Vb 1
465\& like( $this, '/that/', 'this is like that' );
466.Ve
467.Sp
468Regex options may be placed on the end (\f(CW'/that/i'\fR).
469.Sp
470Its advantages over \fIok()\fR are similar to that of \fIis()\fR and \fIisnt()\fR. Better
471diagnostics on failure.
472.IP "\fBunlike\fR" 4
473.IX Item "unlike"
474.Vb 1
475\& unlike( $this, qr/that/, $test_name );
476.Ve
477.Sp
478Works exactly as \fIlike()\fR, only it checks if \f(CW$this\fR \fBdoes not\fR match the
479given pattern.
480.IP "\fBcmp_ok\fR" 4
481.IX Item "cmp_ok"
482.Vb 1
483\& cmp_ok( $this, $op, $that, $test_name );
484.Ve
485.Sp
486Halfway between \fIok()\fR and \fIis()\fR lies \fIcmp_ok()\fR. This allows you to
487compare two arguments using any binary perl operator.
488.Sp
489.Vb 2
490\& # ok( $this eq $that );
491\& cmp_ok( $this, 'eq', $that, 'this eq that' );
492.Ve
493.Sp
494.Vb 2
495\& # ok( $this == $that );
496\& cmp_ok( $this, '==', $that, 'this == that' );
497.Ve
498.Sp
499.Vb 3
500\& # ok( $this && $that );
501\& cmp_ok( $this, '&&', $that, 'this || that' );
502\& ...etc...
503.Ve
504.Sp
505Its advantage over \fIok()\fR is when the test fails you'll know what \f(CW$this\fR
506and \f(CW$that\fR were:
507.Sp
508.Vb 5
509\& not ok 1
510\& # Failed test (foo.t at line 12)
511\& # '23'
512\& # &&
513\& # undef
514.Ve
515.Sp
516It's also useful in those cases where you are comparing numbers and
517\&\fIis()\fR's use of \f(CW\*(C`eq\*(C'\fR will interfere:
518.Sp
519.Vb 1
520\& cmp_ok( $big_hairy_number, '==', $another_big_hairy_number );
521.Ve
522.IP "\fBcan_ok\fR" 4
523.IX Item "can_ok"
524.Vb 2
525\& can_ok($module, @methods);
526\& can_ok($object, @methods);
527.Ve
528.Sp
529Checks to make sure the \f(CW$module\fR or \f(CW$object\fR can do these \f(CW@methods\fR
530(works with functions, too).
531.Sp
532.Vb 1
533\& can_ok('Foo', qw(this that whatever));
534.Ve
535.Sp
536is almost exactly like saying:
537.Sp
538.Vb 4
539\& ok( Foo->can('this') &&
540\& Foo->can('that') &&
541\& Foo->can('whatever')
542\& );
543.Ve
544.Sp
545only without all the typing and with a better interface. Handy for
546quickly testing an interface.
547.Sp
548No matter how many \f(CW@methods\fR you check, a single \fIcan_ok()\fR call counts
549as one test. If you desire otherwise, use:
550.Sp
551.Vb 3
552\& foreach my $meth (@methods) {
553\& can_ok('Foo', $meth);
554\& }
555.Ve
556.IP "\fBisa_ok\fR" 4
557.IX Item "isa_ok"
558.Vb 2
559\& isa_ok($object, $class, $object_name);
560\& isa_ok($ref, $type, $ref_name);
561.Ve
562.Sp
563Checks to see if the given \f(CW$object\fR\->isa($class). Also checks to make
564sure the object was defined in the first place. Handy for this sort
565of thing:
566.Sp
567.Vb 2
568\& my $obj = Some::Module->new;
569\& isa_ok( $obj, 'Some::Module' );
570.Ve
571.Sp
572where you'd otherwise have to write
573.Sp
574.Vb 2
575\& my $obj = Some::Module->new;
576\& ok( defined $obj && $obj->isa('Some::Module') );
577.Ve
578.Sp
579to safeguard against your test script blowing up.
580.Sp
581It works on references, too:
582.Sp
583.Vb 1
584\& isa_ok( $array_ref, 'ARRAY' );
585.Ve
586.Sp
587The diagnostics of this test normally just refer to 'the object'. If
588you'd like them to be more specific, you can supply an \f(CW$object_name\fR
589(for example 'Test customer').
590.IP "\fBpass\fR" 4
591.IX Item "pass"
592.PD 0
593.IP "\fBfail\fR" 4
594.IX Item "fail"
595.PD
596.Vb 2
597\& pass($test_name);
598\& fail($test_name);
599.Ve
600.Sp
601Sometimes you just want to say that the tests have passed. Usually
602the case is you've got some complicated condition that is difficult to
603wedge into an \fIok()\fR. In this case, you can simply use \fIpass()\fR (to
604declare the test ok) or fail (for not ok). They are synonyms for
605\&\fIok\fR\|(1) and \fIok\fR\|(0).
606.Sp
607Use these very, very, very sparingly.
608.Sh "Diagnostics"
609.IX Subsection "Diagnostics"
610If you pick the right test function, you'll usually get a good idea of
611what went wrong when it failed. But sometimes it doesn't work out
612that way. So here we have ways for you to write your own diagnostic
613messages which are safer than just \f(CW\*(C`print STDERR\*(C'\fR.
614.IP "\fBdiag\fR" 4
615.IX Item "diag"
616.Vb 1
617\& diag(@diagnostic_message);
618.Ve
619.Sp
620Prints a diagnostic message which is guaranteed not to interfere with
621test output. Handy for this sort of thing:
622.Sp
623.Vb 2
624\& ok( grep(/foo/, @users), "There's a foo user" ) or
625\& diag("Since there's no foo, check that /etc/bar is set up right");
626.Ve
627.Sp
628which would produce:
629.Sp
630.Vb 3
631\& not ok 42 - There's a foo user
632\& # Failed test (foo.t at line 52)
633\& # Since there's no foo, check that /etc/bar is set up right.
634.Ve
635.Sp
636You might remember \f(CW\*(C`ok() or diag()\*(C'\fR with the mnemonic \f(CW\*(C`open() or
637die()\*(C'\fR.
638.Sp
639\&\fB\s-1NOTE\s0\fR The exact formatting of the diagnostic output is still
640changing, but it is guaranteed that whatever you throw at it it won't
641interfere with the test.
642.Sh "Module tests"
643.IX Subsection "Module tests"
644You usually want to test if the module you're testing loads ok, rather
645than just vomiting if its load fails. For such purposes we have
646\&\f(CW\*(C`use_ok\*(C'\fR and \f(CW\*(C`require_ok\*(C'\fR.
647.IP "\fBuse_ok\fR" 4
648.IX Item "use_ok"
649.Vb 2
650\& BEGIN { use_ok($module); }
651\& BEGIN { use_ok($module, @imports); }
652.Ve
653.Sp
654These simply use the given \f(CW$module\fR and test to make sure the load
655happened ok. It's recommended that you run \fIuse_ok()\fR inside a \s-1BEGIN\s0
656block so its functions are exported at compile-time and prototypes are
657properly honored.
658.Sp
659If \f(CW@imports\fR are given, they are passed through to the use. So this:
660.Sp
661.Vb 1
662\& BEGIN { use_ok('Some::Module', qw(foo bar)) }
663.Ve
664.Sp
665is like doing this:
666.Sp
667.Vb 1
668\& use Some::Module qw(foo bar);
669.Ve
670.Sp
671don't try to do this:
672.Sp
673.Vb 2
674\& BEGIN {
675\& use_ok('Some::Module');
676.Ve
677.Sp
678.Vb 3
679\& ...some code that depends on the use...
680\& ...happening at compile time...
681\& }
682.Ve
683.Sp
684instead, you want:
685.Sp
686.Vb 2
687\& BEGIN { use_ok('Some::Module') }
688\& BEGIN { ...some code that depends on the use... }
689.Ve
690.IP "\fBrequire_ok\fR" 4
691.IX Item "require_ok"
692.Vb 1
693\& require_ok($module);
694.Ve
695.Sp
696Like \fIuse_ok()\fR, except it requires the \f(CW$module\fR.
697.Sh "Conditional tests"
698.IX Subsection "Conditional tests"
699Sometimes running a test under certain conditions will cause the
700test script to die. A certain function or method isn't implemented
701(such as \fIfork()\fR on MacOS), some resource isn't available (like a
702net connection) or a module isn't available. In these cases it's
703necessary to skip tests, or declare that they are supposed to fail
704but will work in the future (a todo test).
705.PP
706For more details on the mechanics of skip and todo tests see
707Test::Harness.
708.PP
709The way Test::More handles this is with a named block. Basically, a
710block of tests which can be skipped over or made todo. It's best if I
711just show you...
712.IP "\fB\s-1SKIP:\s0 \s-1BLOCK\s0\fR" 4
713.IX Item "SKIP: BLOCK"
714.Vb 2
715\& SKIP: {
716\& skip $why, $how_many if $condition;
717.Ve
718.Sp
719.Vb 2
720\& ...normal testing code goes here...
721\& }
722.Ve
723.Sp
724This declares a block of tests that might be skipped, \f(CW$how_many\fR tests
725there are, \f(CW$why\fR and under what \f(CW$condition\fR to skip them. An example is
726the easiest way to illustrate:
727.Sp
728.Vb 2
729\& SKIP: {
730\& eval { require HTML::Lint };
731.Ve
732.Sp
733.Vb 1
734\& skip "HTML::Lint not installed", 2 if $@;
735.Ve
736.Sp
737.Vb 2
738\& my $lint = new HTML::Lint;
739\& ok( $lint, "Created object" );
740.Ve
741.Sp
742.Vb 3
743\& $lint->parse( $html );
744\& is( scalar $lint->errors, 0, "No errors found in HTML" );
745\& }
746.Ve
747.Sp
748If the user does not have HTML::Lint installed, the whole block of
749code \fIwon't be run at all\fR. Test::More will output special ok's
750which Test::Harness interprets as skipped, but passing, tests.
751It's important that \f(CW$how_many\fR accurately reflects the number of tests
752in the \s-1SKIP\s0 block so the # of tests run will match up with your plan.
753.Sp
754It's perfectly safe to nest \s-1SKIP\s0 blocks. Each \s-1SKIP\s0 block must have
755the label \f(CW\*(C`SKIP\*(C'\fR, or Test::More can't work its magic.
756.Sp
757You don't skip tests which are failing because there's a bug in your
758program, or for which you don't yet have code written. For that you
759use \s-1TODO\s0. Read on.
760.IP "\fB\s-1TODO:\s0 \s-1BLOCK\s0\fR" 4
761.IX Item "TODO: BLOCK"
762.Vb 2
763\& TODO: {
764\& local $TODO = $why if $condition;
765.Ve
766.Sp
767.Vb 2
768\& ...normal testing code goes here...
769\& }
770.Ve
771.Sp
772Declares a block of tests you expect to fail and \f(CW$why\fR. Perhaps it's
773because you haven't fixed a bug or haven't finished a new feature:
774.Sp
775.Vb 2
776\& TODO: {
777\& local $TODO = "URI::Geller not finished";
778.Ve
779.Sp
780.Vb 2
781\& my $card = "Eight of clubs";
782\& is( URI::Geller->your_card, $card, 'Is THIS your card?' );
783.Ve
784.Sp
785.Vb 4
786\& my $spoon;
787\& URI::Geller->bend_spoon;
788\& is( $spoon, 'bent', "Spoon bending, that's original" );
789\& }
790.Ve
791.Sp
792With a todo block, the tests inside are expected to fail. Test::More
793will run the tests normally, but print out special flags indicating
794they are \*(L"todo\*(R". Test::Harness will interpret failures as being ok.
795Should anything succeed, it will report it as an unexpected success.
796You then know the thing you had todo is done and can remove the
797\&\s-1TODO\s0 flag.
798.Sp
799The nice part about todo tests, as opposed to simply commenting out a
800block of tests, is it's like having a programmatic todo list. You know
801how much work is left to be done, you're aware of what bugs there are,
802and you'll know immediately when they're fixed.
803.Sp
804Once a todo test starts succeeding, simply move it outside the block.
805When the block is empty, delete it.
806.IP "\fBtodo_skip\fR" 4
807.IX Item "todo_skip"
808.Vb 2
809\& TODO: {
810\& todo_skip $why, $how_many if $condition;
811.Ve
812.Sp
813.Vb 2
814\& ...normal testing code...
815\& }
816.Ve
817.Sp
818With todo tests, it's best to have the tests actually run. That way
819you'll know when they start passing. Sometimes this isn't possible.
820Often a failing test will cause the whole program to die or hang, even
821inside an \f(CW\*(C`eval BLOCK\*(C'\fR with and using \f(CW\*(C`alarm\*(C'\fR. In these extreme
822cases you have no choice but to skip over the broken tests entirely.
823.Sp
824The syntax and behavior is similar to a \f(CW\*(C`SKIP: BLOCK\*(C'\fR except the
825tests will be marked as failing but todo. Test::Harness will
826interpret them as passing.
827.IP "When do I use \s-1SKIP\s0 vs. \s-1TODO\s0?" 4
828.IX Item "When do I use SKIP vs. TODO?"
829\&\fBIf it's something the user might not be able to do\fR, use \s-1SKIP\s0.
830This includes optional modules that aren't installed, running under
831an \s-1OS\s0 that doesn't have some feature (like \fIfork()\fR or symlinks), or maybe
832you need an Internet connection and one isn't available.
833.Sp
834\&\fBIf it's something the programmer hasn't done yet\fR, use \s-1TODO\s0. This
835is for any code you haven't written yet, or bugs you have yet to fix,
836but want to put tests in your testing script (always a good idea).
837.Sh "Comparison functions"
838.IX Subsection "Comparison functions"
839Not everything is a simple eq check or regex. There are times you
840need to see if two arrays are equivalent, for instance. For these
841instances, Test::More provides a handful of useful functions.
842.PP
843\&\fB\s-1NOTE\s0\fR These are \s-1NOT\s0 well-tested on circular references. Nor am I
844quite sure what will happen with filehandles.
845.IP "\fBis_deeply\fR" 4
846.IX Item "is_deeply"
847.Vb 1
848\& is_deeply( $this, $that, $test_name );
849.Ve
850.Sp
851Similar to \fIis()\fR, except that if \f(CW$this\fR and \f(CW$that\fR are hash or array
852references, it does a deep comparison walking each data structure to
853see if they are equivalent. If the two structures are different, it
854will display the place where they start differing.
855.Sp
856Barrie Slaymaker's Test::Differences module provides more in-depth
857functionality along these lines, and it plays well with Test::More.
858.Sp
859\&\fB\s-1NOTE\s0\fR Display of scalar refs is not quite 100%
860.IP "\fBeq_array\fR" 4
861.IX Item "eq_array"
862.Vb 1
863\& eq_array(\e@this, \e@that);
864.Ve
865.Sp
866Checks if two arrays are equivalent. This is a deep check, so
867multi-level structures are handled correctly.
868.IP "\fBeq_hash\fR" 4
869.IX Item "eq_hash"
870.Vb 1
871\& eq_hash(\e%this, \e%that);
872.Ve
873.Sp
874Determines if the two hashes contain the same keys and values. This
875is a deep check.
876.IP "\fBeq_set\fR" 4
877.IX Item "eq_set"
878.Vb 1
879\& eq_set(\e@this, \e@that);
880.Ve
881.Sp
882Similar to \fIeq_array()\fR, except the order of the elements is \fBnot\fR
883important. This is a deep check, but the irrelevancy of order only
884applies to the top level.
885.Sh "Extending and Embedding Test::More"
886.IX Subsection "Extending and Embedding Test::More"
887Sometimes the Test::More interface isn't quite enough. Fortunately,
888Test::More is built on top of Test::Builder which provides a single,
889unified backend for any test library to use. This means two test
890libraries which both use Test::Builder \fBcan be used together in the
891same program\fR.
892.PP
893If you simply want to do a little tweaking of how the tests behave,
894you can access the underlying Test::Builder object like so:
895.IP "\fBbuilder\fR" 4
896.IX Item "builder"
897.Vb 1
898\& my $test_builder = Test::More->builder;
899.Ve
900.Sp
901Returns the Test::Builder object underlying Test::More for you to play
902with.
903.SH "NOTES"
904.IX Header "NOTES"
905Test::More is \fBexplicitly\fR tested all the way back to perl 5.004.
906.PP
907Test::More is thread-safe for perl 5.8.0 and up.
908.SH "BUGS and CAVEATS"
909.IX Header "BUGS and CAVEATS"
910.IP "Making your own \fIok()\fR" 4
911.IX Item "Making your own ok()"
912If you are trying to extend Test::More, don't. Use Test::Builder
913instead.
914.IP "The eq_* family has some caveats." 4
915.IX Item "The eq_* family has some caveats."
916.PD 0
917.IP "Test::Harness upgrades" 4
918.IX Item "Test::Harness upgrades"
919.PD
920no_plan and todo depend on new Test::Harness features and fixes. If
921you're going to distribute tests that use no_plan or todo your
922end-users will have to upgrade Test::Harness to the latest one on
923\&\s-1CPAN\s0. If you avoid no_plan and \s-1TODO\s0 tests, the stock Test::Harness
924will work fine.
925.Sp
926If you simply depend on Test::More, it's own dependencies will cause a
927Test::Harness upgrade.
928.SH "HISTORY"
929.IX Header "HISTORY"
930This is a case of convergent evolution with Joshua Pritikin's Test
931module. I was largely unaware of its existence when I'd first
932written my own \fIok()\fR routines. This module exists because I can't
933figure out how to easily wedge test names into Test's interface (along
934with a few other problems).
935.PP
936The goal here is to have a testing utility that's simple to learn,
937quick to use and difficult to trip yourself up with while still
938providing more flexibility than the existing Test.pm. As such, the
939names of the most common routines are kept tiny, special cases and
940magic side-effects are kept to a minimum. \s-1WYSIWYG\s0.
941.SH "SEE ALSO"
942.IX Header "SEE ALSO"
943Test::Simple if all this confuses you and you just want to write
944some tests. You can upgrade to Test::More later (it's forward
945compatible).
946.PP
947Test::Differences for more ways to test complex data structures.
948And it plays well with Test::More.
949.PP
950Test is the old testing module. Its main benefit is that it has
951been distributed with Perl since 5.004_05.
952.PP
953Test::Harness for details on how your test results are interpreted
954by Perl.
955.PP
956Test::Unit describes a very featureful unit testing interface.
957.PP
958Test::Inline shows the idea of embedded testing.
959.PP
960SelfTest is another approach to embedded testing.
961.SH "AUTHORS"
962.IX Header "AUTHORS"
963Michael G Schwern <schwern@pobox.com> with much inspiration
964from Joshua Pritikin's Test module and lots of help from Barrie
965Slaymaker, Tony Bowden, chromatic and the perl-qa gang.
966.SH "COPYRIGHT"
967.IX Header "COPYRIGHT"
968Copyright 2001 by Michael G Schwern <schwern@pobox.com>.
969.PP
970This program is free software; you can redistribute it and/or
971modify it under the same terms as Perl itself.
972.PP
973See \fIhttp://www.perl.com/perl/misc/Artistic.html\fR