Debian Codegraph @

upstream/opensuse-tumbleweed/man3/Test::Simple.3pm

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