Debian Codegraph @

upstream/debian-unstable/man3/Test::Simple.3perl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "Test::Simple 3perl"
58 .TH Test::Simple 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide"
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 Test::Simple \- Basic utilities for writing tests.
65 .SH SYNOPSIS
66 .IX Header "SYNOPSIS"
67 .Vb 1
68 \& use Test::Simple tests => 1;
69 \&
70 \& ok( $foo eq $bar, \*(Aqfoo is bar\*(Aq );
71 .Ve
72 .SH DESCRIPTION
73 .IX Header "DESCRIPTION"
74 ** If you are unfamiliar with testing \fBread Test::Tutorial first!\fR **
75 .PP
76 This is an extremely simple, extremely basic module for writing tests
77 suitable for CPAN modules and other pursuits. If you wish to do more
78 complicated testing, use the Test::More module (a drop-in replacement
79 for this one).
80 .PP
81 The basic unit of Perl testing is the ok. For each thing you want to
82 test your program will print out an "ok" or "not ok" to indicate pass
83 or fail. You do this with the \f(CWok()\fR function (see below).
84 .PP
85 The only other constraint is you must pre-declare how many tests you
86 plan to run. This is in case something goes horribly wrong during the
87 test and your test program aborts, or skips a test or whatever. You
88 do this like so:
89 .PP
90 .Vb 1
91 \& use Test::Simple tests => 23;
92 .Ve
93 .PP
94 You must have a plan.
95 .IP \fBok\fR 4
96 .IX Item "ok"
97 .Vb 2
98 \& ok( $foo eq $bar, $name );
99 \& ok( $foo eq $bar );
100 .Ve
101 .Sp
102 \&\f(CWok()\fR is given an expression (in this case \f(CW\*(C`$foo eq $bar\*(C'\fR). If it's
103 true, the test passed. If it's false, it didn't. That's about it.
104 .Sp
105 \&\f(CWok()\fR prints out either "ok" or "not ok" along with a test number (it
106 keeps track of that for you).
107 .Sp
108 .Vb 2
109 \& # This produces "ok 1 \- Hell not yet frozen over" (or not ok)
110 \& ok( get_temperature($hell) > 0, \*(AqHell not yet frozen over\*(Aq );
111 .Ve
112 .Sp
113 If you provide a \f(CW$name\fR, that will be printed along with the "ok/not
114 ok" to make it easier to find your test when if fails (just search for
115 the name). It also makes it easier for the next guy to understand
116 what your test is for. It's highly recommended you use test names.
117 .Sp
118 All tests are run in scalar context. So this:
119 .Sp
120 .Vb 1
121 \& ok( @stuff, \*(AqI have some stuff\*(Aq );
122 .Ve
123 .Sp
124 will do what you mean (fail if stuff is empty)
125 .PP
126 Test::Simple will start by printing number of tests run in the form
127 "1..M" (so "1..5" means you're going to run 5 tests). This strange
128 format lets Test::Harness know how many tests you plan on running in
129 case something goes horribly wrong.
130 .PP
131 If all your tests passed, Test::Simple will exit with zero (which is
132 normal). If anything failed it will exit with how many failed. If
133 you run less (or more) tests than you planned, the missing (or extras)
134 will be considered failures. If no tests were ever run Test::Simple
135 will throw a warning and exit with 255. If the test died, even after
136 having successfully completed all its tests, it will still be
137 considered a failure and will exit with 255.
138 .PP
139 So the exit codes are...
140 .PP
141 .Vb 3
142 \& 0 all tests successful
143 \& 255 test died or all passed but wrong # of tests run
144 \& any other number how many failed (including missing or extras)
145 .Ve
146 .PP
147 If you fail more than 254 tests, it will be reported as 254.
148 .PP
149 This module is by no means trying to be a complete testing system.
150 It's just to get you started. Once you're off the ground its
151 recommended you look at Test::More.
152 .SH EXAMPLE
153 .IX Header "EXAMPLE"
154 Here's an example of a simple .t file for the fictional Film module.
155 .PP
156 .Vb 1
157 \& use Test::Simple tests => 5;
158 \&
159 \& use Film; # What you\*(Aqre testing.
160 \&
161 \& my $btaste = Film\->new({ Title => \*(AqBad Taste\*(Aq,
162 \& Director => \*(AqPeter Jackson\*(Aq,
163 \& Rating => \*(AqR\*(Aq,
164 \& NumExplodingSheep => 1
165 \& });
166 \& ok( defined($btaste) && ref $btaste eq \*(AqFilm\*(Aq, \*(Aqnew() works\*(Aq );
167 \&
168 \& ok( $btaste\->Title eq \*(AqBad Taste\*(Aq, \*(AqTitle() get\*(Aq );
169 \& ok( $btaste\->Director eq \*(AqPeter Jackson\*(Aq, \*(AqDirector() get\*(Aq );
170 \& ok( $btaste\->Rating eq \*(AqR\*(Aq, \*(AqRating() get\*(Aq );
171 \& ok( $btaste\->NumExplodingSheep == 1, \*(AqNumExplodingSheep() get\*(Aq );
172 .Ve
173 .PP
174 It will produce output like this:
175 .PP
176 .Vb 9
177 \& 1..5
178 \& ok 1 \- new() works
179 \& ok 2 \- Title() get
180 \& ok 3 \- Director() get
181 \& not ok 4 \- Rating() get
182 \& # Failed test \*(AqRating() get\*(Aq
183 \& # in t/film.t at line 14.
184 \& ok 5 \- NumExplodingSheep() get
185 \& # Looks like you failed 1 tests of 5
186 .Ve
187 .PP
188 Indicating the \fBFilm::Rating()\fR method is broken.
189 .SH CAVEATS
190 .IX Header "CAVEATS"
191 Test::Simple will only report a maximum of 254 failures in its exit
192 code. If this is a problem, you probably have a huge test script.
193 Split it into multiple files. (Otherwise blame the Unix folks for
194 using an unsigned short integer as the exit status).
195 .PP
196 Because VMS's exit codes are much, much different than the rest of the
197 universe, and perl does horrible mangling to them that gets in my way,
198 it works like this on VMS.
199 .PP
200 .Vb 2
201 \& 0 SS$_NORMAL all tests successful
202 \& 4 SS$_ABORT something went wrong
203 .Ve
204 .PP
205 Unfortunately, I can't differentiate any further.
206 .SH NOTES
207 .IX Header "NOTES"
208 Test::Simple is \fBexplicitly\fR tested all the way back to perl 5.6.0.
209 .PP
210 Test::Simple is thread-safe in perl 5.8.1 and up.
211 .SH HISTORY
212 .IX Header "HISTORY"
213 This module was conceived while talking with Tony Bowden in his
214 kitchen one night about the problems I was having writing some really
215 complicated feature into the new Testing module. He observed that the
216 main problem is not dealing with these edge cases but that people hate
217 to write tests \fBat all\fR. What was needed was a dead simple module
218 that took all the hard work out of testing and was really, really easy
219 to learn. Paul Johnson simultaneously had this idea (unfortunately,
220 he wasn't in Tony's kitchen). This is it.
221 .SH "SEE ALSO"
222 .IX Header "SEE ALSO"
223 .IP Test::More 4
224 .IX Item "Test::More"
225 More testing functions! Once you outgrow Test::Simple, look at
226 Test::More. Test::Simple is 100% forward compatible with Test::More
227 (i.e. you can just use Test::More instead of Test::Simple in your
228 programs and things will still work).
229 .PP
230 Look in Test::More's SEE ALSO for more testing modules.
231 .SH AUTHORS
232 .IX Header "AUTHORS"
233 Idea by Tony Bowden and Paul Johnson, code by Michael G Schwern
234 <[email protected]>, wardrobe by Calvin Klein.
235 .SH MAINTAINERS
236 .IX Header "MAINTAINERS"
237 .IP "Chad Granum <[email protected]>" 4
238 .IX Item "Chad Granum <[email protected]>"
239 .SH COPYRIGHT
240 .IX Header "COPYRIGHT"
241 Copyright 2001\-2008 by Michael G Schwern <[email protected]>.
242 .PP
243 This program is free software; you can redistribute it and/or
244 modify it under the same terms as Perl itself.
245 .PP
246 See <https://dev.perl.org/licenses/>