Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / man / man3 / Test.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 3"
132.TH Test 3 "2002-06-01" "perl v5.8.0" "Perl Programmers Reference Guide"
133.SH "NAME"
134Test \- provides a simple framework for writing test scripts
135.SH "SYNOPSIS"
136.IX Header "SYNOPSIS"
137.Vb 2
138\& use strict;
139\& use Test;
140.Ve
141.PP
142.Vb 2
143\& # use a BEGIN block so we print our plan before MyModule is loaded
144\& BEGIN { plan tests => 14, todo => [3,4] }
145.Ve
146.PP
147.Vb 2
148\& # load your module...
149\& use MyModule;
150.Ve
151.PP
152.Vb 2
153\& ok(0); # failure
154\& ok(1); # success
155.Ve
156.PP
157.Vb 2
158\& ok(0); # ok, expected failure (see todo list, above)
159\& ok(1); # surprise success!
160.Ve
161.PP
162.Vb 4
163\& ok(0,1); # failure: '0' ne '1'
164\& ok('broke','fixed'); # failure: 'broke' ne 'fixed'
165\& ok('fixed','fixed'); # success: 'fixed' eq 'fixed'
166\& ok('fixed',qr/x/); # success: 'fixed' =~ qr/x/
167.Ve
168.PP
169.Vb 3
170\& ok(sub { 1+1 }, 2); # success: '2' eq '2'
171\& ok(sub { 1+1 }, 3); # failure: '2' ne '3'
172\& ok(0, int(rand(2)); # (just kidding :-)
173.Ve
174.PP
175.Vb 3
176\& my @list = (0,0);
177\& ok @list, 3, "\e@list=".join(',',@list); #extra diagnostics
178\& ok 'segmentation fault', '/(?i)success/'; #regex match
179.Ve
180.PP
181.Vb 1
182\& skip($feature_is_missing, ...); #do platform specific test
183.Ve
184.SH "DESCRIPTION"
185.IX Header "DESCRIPTION"
186\&\fB\s-1STOP\s0!\fR If you are writing a new test, we \fIhighly suggest\fR you use
187the new Test::Simple and Test::More modules instead.
188.PP
189Test::Harness expects to see particular output when it
190executes tests. This module aims to make writing proper test scripts just
191a little bit easier (and less error prone :\-).
192.Sh "Functions"
193.IX Subsection "Functions"
194All the following are exported by Test by default.
195.IP "\fBplan\fR" 4
196.IX Item "plan"
197.Vb 1
198\& BEGIN { plan %theplan; }
199.Ve
200.Sp
201This should be the first thing you call in your test script. It
202declares your testing plan, how many there will be, if any of them
203should be allowed to fail, etc...
204.Sp
205Typical usage is just:
206.Sp
207.Vb 2
208\& use Test;
209\& BEGIN { plan tests => 23 }
210.Ve
211.Sp
212Things you can put in the plan:
213.Sp
214.Vb 7
215\& tests The number of tests in your script.
216\& This means all ok() and skip() calls.
217\& todo A reference to a list of tests which are allowed
218\& to fail. See L</TODO TESTS>.
219\& onfail A subroutine reference to be run at the end of
220\& the test script should any of the tests fail.
221\& See L</ONFAIL>.
222.Ve
223.Sp
224You must call \fIplan()\fR once and only once.
225.IP "\fBok\fR" 4
226.IX Item "ok"
227.Vb 3
228\& ok(1 + 1 == 2);
229\& ok($have, $expect);
230\& ok($have, $expect, $diagnostics);
231.Ve
232.Sp
233This is the reason for Test's existance. Its the basic function that
234handles printing \*(L"ok\*(R" or \*(L"not ok\*(R" along with the current test number.
235.Sp
236In its most basic usage, it simply takes an expression. If its true,
237the test passes, if false, the test fails. Simp.
238.Sp
239.Vb 5
240\& ok( 1 + 1 == 2 ); # ok if 1 + 1 == 2
241\& ok( $foo =~ /bar/ ); # ok if $foo contains 'bar'
242\& ok( baz($x + $y) eq 'Armondo' ); # ok if baz($x + $y) returns
243\& # 'Armondo'
244\& ok( @a == @b ); # ok if @a and @b are the same length
245.Ve
246.Sp
247The expression is evaluated in scalar context. So the following will
248work:
249.Sp
250.Vb 3
251\& ok( @stuff ); # ok if @stuff has any elements
252\& ok( !grep !defined $_, @stuff ); # ok if everything in @stuff is
253\& # defined.
254.Ve
255.Sp
256A special case is if the expression is a subroutine reference. In
257that case, it is executed and its value (true or false) determines if
258the test passes or fails.
259.Sp
260In its two argument form it compares the two values to see if they
261equal (with \f(CW\*(C`eq\*(C'\fR).
262.Sp
263.Vb 1
264\& ok( "this", "that" ); # not ok, 'this' ne 'that'
265.Ve
266.Sp
267If either is a subroutine reference, that is run and used as a
268comparison.
269.Sp
270Should \f(CW$expect\fR either be a regex reference (ie. qr//) or a string that
271looks like a regex (ie. '/foo/') \fIok()\fR will perform a pattern match
272against it rather than using eq.
273.Sp
274.Vb 3
275\& ok( 'JaffO', '/Jaff/' ); # ok, 'JaffO' =~ /Jaff/
276\& ok( 'JaffO', qr/Jaff/ ); # ok, 'JaffO' =~ qr/Jaff/;
277\& ok( 'JaffO', '/(?i)jaff/ ); # ok, 'JaffO' =~ /jaff/i;
278.Ve
279.Sp
280Finally, an optional set of \f(CW$diagnostics\fR will be printed should the
281test fail. This should usually be some useful information about the
282test pertaining to why it failed or perhaps a description of the test.
283Or both.
284.Sp
285.Vb 4
286\& ok( grep($_ eq 'something unique', @stuff), 1,
287\& "Something that should be unique isn't!\en".
288\& '@stuff = '.join ', ', @stuff
289\& );
290.Ve
291.Sp
292Unfortunately, a diagnostic cannot be used with the single argument
293style of \fIok()\fR.
294.Sp
295All these special cases can cause some problems. See \*(L"\s-1BUGS\s0 and \s-1CAVEATS\s0\*(R".
296.SH "TEST TYPES"
297.IX Header "TEST TYPES"
298.IP "\(bu \s-1NORMAL\s0 \s-1TESTS\s0" 4
299.IX Item "NORMAL TESTS"
300These tests are expected to succeed. If they don't something's
301screwed up!
302.IP "\(bu \s-1SKIPPED\s0 \s-1TESTS\s0" 4
303.IX Item "SKIPPED TESTS"
304Skip is for tests that might or might not be possible to run depending
305on the availability of platform specific features. The first argument
306should evaluate to true (think \*(L"yes, please skip\*(R") if the required
307feature is not available. After the first argument, skip works
308exactly the same way as do normal tests.
309.IP "\(bu \s-1TODO\s0 \s-1TESTS\s0" 4
310.IX Item "TODO TESTS"
311\&\s-1TODO\s0 tests are designed for maintaining an \fBexecutable \s-1TODO\s0 list\fR.
312These tests are expected \s-1NOT\s0 to succeed. If a \s-1TODO\s0 test does succeed,
313the feature in question should not be on the \s-1TODO\s0 list, now should it?
314.Sp
315Packages should \s-1NOT\s0 be released with succeeding \s-1TODO\s0 tests. As soon
316as a \s-1TODO\s0 test starts working, it should be promoted to a normal test
317and the newly working feature should be documented in the release
318notes or change log.
319.SH "ONFAIL"
320.IX Header "ONFAIL"
321.Vb 1
322\& BEGIN { plan test => 4, onfail => sub { warn "CALL 911!" } }
323.Ve
324.PP
325While test failures should be enough, extra diagnostics can be
326triggered at the end of a test run. \f(CW\*(C`onfail\*(C'\fR is passed an array ref
327of hash refs that describe each test failure. Each hash will contain
328at least the following fields: \f(CW\*(C`package\*(C'\fR, \f(CW\*(C`repetition\*(C'\fR, and
329\&\f(CW\*(C`result\*(C'\fR. (The file, line, and test number are not included because
330their correspondence to a particular test is tenuous.) If the test
331had an expected value or a diagnostic string, these will also be
332included.
333.PP
334The \fBoptional\fR \f(CW\*(C`onfail\*(C'\fR hook might be used simply to print out the
335version of your package and/or how to report problems. It might also
336be used to generate extremely sophisticated diagnostics for a
337particularly bizarre test failure. However it's not a panacea. Core
338dumps or other unrecoverable errors prevent the \f(CW\*(C`onfail\*(C'\fR hook from
339running. (It is run inside an \f(CW\*(C`END\*(C'\fR block.) Besides, \f(CW\*(C`onfail\*(C'\fR is
340probably over-kill in most cases. (Your test code should be simpler
341than the code it is testing, yes?)
342.SH "BUGS and CAVEATS"
343.IX Header "BUGS and CAVEATS"
344\&\fIok()\fR's special handling of subroutine references is an unfortunate
345\&\*(L"feature\*(R" that can't be removed due to compatibility.
346.PP
347\&\fIok()\fR's use of string eq can sometimes cause odd problems when comparing
348numbers, especially if you're casting a string to a number:
349.PP
350.Vb 2
351\& $foo = "1.0";
352\& ok( $foo, 1 ); # not ok, "1.0" ne 1
353.Ve
354.PP
355Your best bet is to use the single argument form:
356.PP
357.Vb 1
358\& ok( $foo == 1 ); # ok "1.0" == 1
359.Ve
360.PP
361\&\fIok()\fR's special handing of strings which look like they might be
362regexes can also cause unexpected behavior. An innocent:
363.PP
364.Vb 1
365\& ok( $fileglob, '/path/to/some/*stuff/' );
366.Ve
367.PP
368will fail since Test.pm considers the second argument to a regex.
369Again, best bet is to use the single argument form:
370.PP
371.Vb 1
372\& ok( $fileglob eq '/path/to/some/*stuff/' );
373.Ve
374.SH "NOTE"
375.IX Header "NOTE"
376This module is no longer actively being developed, only bug fixes and
377small tweaks (I'll still accept patches). If you desire additional
378functionality, consider Test::More or Test::Unit.
379.SH "SEE ALSO"
380.IX Header "SEE ALSO"
381Test::Simple, Test::More, Test::Harness, Devel::Cover
382.PP
383Test::Builder for building your own testing library.
384.PP
385Test::Unit is an interesting XUnit-style testing library.
386.PP
387Test::Inline and SelfTest let you embed tests in code.
388.SH "AUTHOR"
389.IX Header "AUTHOR"
390Copyright (c) 1998\-2000 Joshua Nathaniel Pritikin. All rights reserved.
391Copyright (c) 2001\-2002 Michael G Schwern.
392.PP
393Current maintainer, Michael G Schwern <schwern@pobox.com>
394.PP
395This package is free software and is provided \*(L"as is\*(R" without express
396or implied warranty. It may be used, redistributed and/or modified
397under the same terms as Perl itself.