Add built local::lib
[catagits/Gitalist.git] / local-lib5 / man / man3 / Test::Simple.3pm
1 .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.3
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::Simple 3"
132 .TH Test::Simple 3 "2009-09-02" "perl v5.8.7" "User Contributed Perl Documentation"
133 .SH "NAME"
134 Test::Simple \- Basic utilities for writing tests.
135 .SH "SYNOPSIS"
136 .IX Header "SYNOPSIS"
137 .Vb 1
138 \&  use Test::Simple tests => 1;
139 .Ve
140 .PP
141 .Vb 1
142 \&  ok( $foo eq $bar, 'foo is bar' );
143 .Ve
144 .SH "DESCRIPTION"
145 .IX Header "DESCRIPTION"
146 ** If you are unfamiliar with testing \fBread Test::Tutorial\fR first! **
147 .PP
148 This is an extremely simple, extremely basic module for writing tests
149 suitable for \s-1CPAN\s0 modules and other pursuits.  If you wish to do more
150 complicated testing, use the Test::More module (a drop-in replacement
151 for this one).
152 .PP
153 The basic unit of Perl testing is the ok.  For each thing you want to
154 test your program will print out an \*(L"ok\*(R" or \*(L"not ok\*(R" to indicate pass
155 or fail.  You do this with the \fIok()\fR function (see below).
156 .PP
157 The only other constraint is you must pre-declare how many tests you
158 plan to run.  This is in case something goes horribly wrong during the
159 test and your test program aborts, or skips a test or whatever.  You
160 do this like so:
161 .PP
162 .Vb 1
163 \&    use Test::Simple tests => 23;
164 .Ve
165 .PP
166 You must have a plan.
167 .IP "\fBok\fR" 4
168 .IX Item "ok"
169 .Vb 2
170 \&  ok( $foo eq $bar, $name );
171 \&  ok( $foo eq $bar );
172 .Ve
173 .Sp
174 \&\fIok()\fR is given an expression (in this case \f(CW\*(C`$foo eq $bar\*(C'\fR).  If it's
175 true, the test passed.  If it's false, it didn't.  That's about it.
176 .Sp
177 \&\fIok()\fR prints out either \*(L"ok\*(R" or \*(L"not ok\*(R" along with a test number (it
178 keeps track of that for you).
179 .Sp
180 .Vb 2
181 \&  # This produces "ok 1 \- Hell not yet frozen over" (or not ok)
182 \&  ok( get_temperature($hell) > 0, 'Hell not yet frozen over' );
183 .Ve
184 .Sp
185 If you provide a \f(CW$name\fR, that will be printed along with the \*(L"ok/not
186 ok\*(R" to make it easier to find your test when if fails (just search for
187 the name).  It also makes it easier for the next guy to understand
188 what your test is for.  It's highly recommended you use test names.
189 .Sp
190 All tests are run in scalar context.  So this:
191 .Sp
192 .Vb 1
193 \&    ok( @stuff, 'I have some stuff' );
194 .Ve
195 .Sp
196 will do what you mean (fail if stuff is empty)
197 .PP
198 Test::Simple will start by printing number of tests run in the form
199 \&\*(L"1..M\*(R" (so \*(L"1..5\*(R" means you're going to run 5 tests).  This strange
200 format lets Test::Harness know how many tests you plan on running in
201 case something goes horribly wrong.
202 .PP
203 If all your tests passed, Test::Simple will exit with zero (which is
204 normal).  If anything failed it will exit with how many failed.  If
205 you run less (or more) tests than you planned, the missing (or extras)
206 will be considered failures.  If no tests were ever run Test::Simple
207 will throw a warning and exit with 255.  If the test died, even after
208 having successfully completed all its tests, it will still be
209 considered a failure and will exit with 255.
210 .PP
211 So the exit codes are...
212 .PP
213 .Vb 3
214 \&    0                   all tests successful
215 \&    255                 test died or all passed but wrong # of tests run
216 \&    any other number    how many failed (including missing or extras)
217 .Ve
218 .PP
219 If you fail more than 254 tests, it will be reported as 254.
220 .PP
221 This module is by no means trying to be a complete testing system.
222 It's just to get you started.  Once you're off the ground its
223 recommended you look at Test::More.
224 .SH "EXAMPLE"
225 .IX Header "EXAMPLE"
226 Here's an example of a simple .t file for the fictional Film module.
227 .PP
228 .Vb 1
229 \&    use Test::Simple tests => 5;
230 .Ve
231 .PP
232 .Vb 1
233 \&    use Film;  # What you're testing.
234 .Ve
235 .PP
236 .Vb 6
237 \&    my $btaste = Film\->new({ Title    => 'Bad Taste',
238 \&                             Director => 'Peter Jackson',
239 \&                             Rating   => 'R',
240 \&                             NumExplodingSheep => 1
241 \&                           });
242 \&    ok( defined($btaste) && ref $btaste eq 'Film,     'new() works' );
243 .Ve
244 .PP
245 .Vb 4
246 \&    ok( $btaste\->Title      eq 'Bad Taste',     'Title() get'    );
247 \&    ok( $btaste\->Director   eq 'Peter Jackson', 'Director() get' );
248 \&    ok( $btaste\->Rating     eq 'R',             'Rating() get'   );
249 \&    ok( $btaste\->NumExplodingSheep == 1,        'NumExplodingSheep() get' );
250 .Ve
251 .PP
252 It will produce output like this:
253 .PP
254 .Vb 9
255 \&    1..5
256 \&    ok 1 \- new() works
257 \&    ok 2 \- Title() get
258 \&    ok 3 \- Director() get
259 \&    not ok 4 \- Rating() get
260 \&    #   Failed test 'Rating() get'
261 \&    #   in t/film.t at line 14.
262 \&    ok 5 \- NumExplodingSheep() get
263 \&    # Looks like you failed 1 tests of 5
264 .Ve
265 .PP
266 Indicating the \fIFilm::Rating()\fR method is broken.
267 .SH "CAVEATS"
268 .IX Header "CAVEATS"
269 Test::Simple will only report a maximum of 254 failures in its exit
270 code.  If this is a problem, you probably have a huge test script.
271 Split it into multiple files.  (Otherwise blame the Unix folks for
272 using an unsigned short integer as the exit status).
273 .PP
274 Because \s-1VMS\s0's exit codes are much, much different than the rest of the
275 universe, and perl does horrible mangling to them that gets in my way,
276 it works like this on \s-1VMS\s0.
277 .PP
278 .Vb 2
279 \&    0     SS$_NORMAL        all tests successful
280 \&    4     SS$_ABORT         something went wrong
281 .Ve
282 .PP
283 Unfortunately, I can't differentiate any further.
284 .SH "NOTES"
285 .IX Header "NOTES"
286 Test::Simple is \fBexplicitly\fR tested all the way back to perl 5.6.0.
287 .PP
288 Test::Simple is thread-safe in perl 5.8.1 and up.
289 .SH "HISTORY"
290 .IX Header "HISTORY"
291 This module was conceived while talking with Tony Bowden in his
292 kitchen one night about the problems I was having writing some really
293 complicated feature into the new Testing module.  He observed that the
294 main problem is not dealing with these edge cases but that people hate
295 to write tests \fBat all\fR.  What was needed was a dead simple module
296 that took all the hard work out of testing and was really, really easy
297 to learn.  Paul Johnson simultaneously had this idea (unfortunately,
298 he wasn't in Tony's kitchen).  This is it.
299 .SH "SEE ALSO"
300 .IX Header "SEE ALSO"
301 .IP "Test::More" 4
302 .IX Item "Test::More"
303 More testing functions!  Once you outgrow Test::Simple, look at
304 Test::More.  Test::Simple is 100% forward compatible with Test::More
305 (i.e. you can just use Test::More instead of Test::Simple in your
306 programs and things will still work).
307 .PP
308 Look in Test::More's \s-1SEE\s0 \s-1ALSO\s0 for more testing modules.
309 .SH "AUTHORS"
310 .IX Header "AUTHORS"
311 Idea by Tony Bowden and Paul Johnson, code by Michael G Schwern
312 <schwern@pobox.com>, wardrobe by Calvin Klein.
313 .SH "COPYRIGHT"
314 .IX Header "COPYRIGHT"
315 Copyright 2001\-2008 by Michael G Schwern <schwern@pobox.com>.
316 .PP
317 This program is free software; you can redistribute it and/or 
318 modify it under the same terms as Perl itself.
319 .PP
320 See \fIhttp://www.perl.com/perl/misc/Artistic.html\fR