Debian Codegraph @

upstream/opensuse-tumbleweed/man3/Test2::Tools::Basic.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 "Test2::Tools::Basic 3pm"
61 .TH Test2::Tools::Basic 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 Test2::Tools::Basic \- Test2 implementation of the basic testing tools.
68 .SH DESCRIPTION
69 .IX Header "DESCRIPTION"
70 This is a Test2 based implementation of the more basic tools originally
71 provided by Test::More. Not all Test::More tools are provided by this
72 package, only the basic/simple ones. Some tools have been modified for better
73 diagnostics capabilities.
74 .SH SYNOPSIS
75 .IX Header "SYNOPSIS"
76 .Vb 1
77 \& use Test2::Tools::Basic;
78 \&
79 \& ok($x, "simple test");
80 \&
81 \& if ($passing) {
82 \& pass(\*(Aqa passing test\*(Aq);
83 \& }
84 \& else {
85 \& fail(\*(Aqa failing test\*(Aq);
86 \& }
87 \&
88 \& diag "This is a diagnostics message on STDERR";
89 \& note "This is a diagnostics message on STDOUT";
90 \&
91 \& {
92 \& my $todo = todo "Reason for todo";
93 \& ok(0, "this test is todo");
94 \& }
95 \&
96 \& ok(1, "this test is not todo");
97 \&
98 \& todo "reason" => sub {
99 \& ok(0, "this test is todo");
100 \& };
101 \&
102 \& ok(1, "this test is not todo");
103 \&
104 \& SKIP: {
105 \& skip "This will wipe your drive";
106 \&
107 \& # This never gets run:
108 \& ok(!system(\*(Aqsudo rm \-rf /\*(Aq), "Wipe drive");
109 \& }
110 \&
111 \& done_testing;
112 .Ve
113 .SH EXPORTS
114 .IX Header "EXPORTS"
115 All subs are exported by default.
116 .SS PLANNING
117 .IX Subsection "PLANNING"
118 .IP plan($num) 4
119 .IX Item "plan($num)"
120 .PD 0
121 .ie n .IP "plan(\*(Aqtests\*(Aq => $num)" 4
122 .el .IP "plan(\*(Aqtests\*(Aq => \f(CW$num\fR)" 4
123 .IX Item "plan('tests' => $num)"
124 .ie n .IP "plan(\*(Aqskip_all\*(Aq => $reason)" 4
125 .el .IP "plan(\*(Aqskip_all\*(Aq => \f(CW$reason\fR)" 4
126 .IX Item "plan('skip_all' => $reason)"
127 .PD
128 Set the number of tests that are expected. This must be done first or last,
129 never in the middle of testing.
130 .Sp
131 For legacy compatibility you can specify \*(Aqtests\*(Aq as the first argument before
132 the number. You can also use this to skip all with the \*(Aqskip_all\*(Aq prefix,
133 followed by a reason for skipping.
134 .IP skip_all($reason) 4
135 .IX Item "skip_all($reason)"
136 Set the plan to 0 with a reason, then exit true. This should be used before any
137 tests are run.
138 .IP done_testing 4
139 .IX Item "done_testing"
140 Used to mark the end of testing. This is a safe way to have a dynamic or
141 unknown number of tests.
142 .IP bail_out($reason) 4
143 .IX Item "bail_out($reason)"
144 Invoked when something has gone horribly wrong: stop everything, kill all threads and
145 processes, end the process with a false exit status.
146 .SS ASSERTIONS
147 .IX Subsection "ASSERTIONS"
148 .IP ok($bool) 4
149 .IX Item "ok($bool)"
150 .PD 0
151 .ie n .IP "ok($bool, $name)" 4
152 .el .IP "ok($bool, \f(CW$name\fR)" 4
153 .IX Item "ok($bool, $name)"
154 .ie n .IP "ok($bool, $name, @diag)" 4
155 .el .IP "ok($bool, \f(CW$name\fR, \f(CW@diag\fR)" 4
156 .IX Item "ok($bool, $name, @diag)"
157 .PD
158 Simple assertion. If \f(CW$bool\fR is true the test passes, and if it is false the test
159 fails. The test name is optional, and all arguments after the name are added as
160 diagnostics message if and only if the test fails. If the test passes all the
161 diagnostics arguments will be ignored.
162 .IP \fBpass()\fR 4
163 .IX Item "pass()"
164 .PD 0
165 .IP pass($name) 4
166 .IX Item "pass($name)"
167 .PD
168 Fire off a passing test (a single Ok event). The name is optional
169 .IP \fBfail()\fR 4
170 .IX Item "fail()"
171 .PD 0
172 .IP fail($name) 4
173 .IX Item "fail($name)"
174 .ie n .IP "fail($name, @diag)" 4
175 .el .IP "fail($name, \f(CW@diag\fR)" 4
176 .IX Item "fail($name, @diag)"
177 .PD
178 Fire off a failing test (a single Ok event). The name and diagnostics are optional.
179 .SS DIAGNOSTICS
180 .IX Subsection "DIAGNOSTICS"
181 .IP diag(@messages) 4
182 .IX Item "diag(@messages)"
183 Write diagnostics messages. All items in \f(CW@messages\fR will be joined into a
184 single string with no separator. When using TAP, diagnostics are sent to STDERR.
185 .Sp
186 Returns false, so as to preserve failure.
187 .IP note(@messages) 4
188 .IX Item "note(@messages)"
189 Write note\-diagnostics messages. All items in \f(CW@messages\fR will be joined into
190 a single string with no separator. When using TAP, notes are sent to STDOUT.
191 .SS META
192 .IX Subsection "META"
193 .ie n .IP "$todo = todo($reason)" 4
194 .el .IP "\f(CW$todo\fR = todo($reason)" 4
195 .IX Item "$todo = todo($reason)"
196 .PD 0
197 .ie n .IP "todo $reason => sub { ... }" 4
198 .el .IP "todo \f(CW$reason\fR => sub { ... }" 4
199 .IX Item "todo $reason => sub { ... }"
200 .PD
201 This is used to mark some results as TODO. TODO means that the test may fail,
202 but will not cause the overall test suite to fail.
203 .Sp
204 There are two ways to use this. The first is to use a codeblock, and the TODO will
205 only apply to the codeblock.
206 .Sp
207 .Vb 1
208 \& ok(1, "before"); # Not TODO
209 \&
210 \& todo \*(Aqthis will fail\*(Aq => sub {
211 \& # This is TODO, as is any other test in this block.
212 \& ok(0, "blah");
213 \& };
214 \&
215 \& ok(1, "after"); # Not TODO
216 .Ve
217 .Sp
218 The other way is to use a scoped variable. TODO will end when the variable is
219 destroyed or set to undef.
220 .Sp
221 .Vb 1
222 \& ok(1, "before"); # Not TODO
223 \&
224 \& {
225 \& my $todo = todo \*(Aqthis will fail\*(Aq;
226 \&
227 \& # This is TODO, as is any other test in this block.
228 \& ok(0, "blah");
229 \& };
230 \&
231 \& ok(1, "after"); # Not TODO
232 .Ve
233 .Sp
234 This is the same thing, but without the \f(CW\*(C`{...}\*(C'\fR scope.
235 .Sp
236 .Vb 1
237 \& ok(1, "before"); # Not TODO
238 \&
239 \& my $todo = todo \*(Aqthis will fail\*(Aq;
240 \&
241 \& ok(0, "blah"); # TODO
242 \&
243 \& $todo = undef;
244 \&
245 \& ok(1, "after"); # Not TODO
246 .Ve
247 .IP skip($why) 4
248 .IX Item "skip($why)"
249 .PD 0
250 .ie n .IP "skip($why, $count)" 4
251 .el .IP "skip($why, \f(CW$count\fR)" 4
252 .IX Item "skip($why, $count)"
253 .PD
254 This is used to skip some tests. This requires you to wrap your tests in a
255 block labeled \f(CW\*(C`SKIP:\*(C'\fR. This is somewhat magical. If no \f(CW$count\fR is specified
256 then it will issue a single result. If you specify \f(CW$count\fR it will issue that
257 many results.
258 .Sp
259 .Vb 2
260 \& SKIP: {
261 \& skip "This will wipe your drive";
262 \&
263 \& # This never gets run:
264 \& ok(!system(\*(Aqsudo rm \-rf /\*(Aq), "Wipe drive");
265 \& }
266 .Ve
267 .SH SOURCE
268 .IX Header "SOURCE"
269 The source code repository for Test2\-Suite can be found at
270 \&\fIhttps://github.com/Test\-More/test\-more/\fR.
271 .SH MAINTAINERS
272 .IX Header "MAINTAINERS"
273 .IP "Chad Granum <[email protected]>" 4
274 .IX Item "Chad Granum <[email protected]>"
275 .SH AUTHORS
276 .IX Header "AUTHORS"
277 .IP "Chad Granum <[email protected]>" 4
278 .IX Item "Chad Granum <[email protected]>"
279 .SH COPYRIGHT
280 .IX Header "COPYRIGHT"
281 Copyright Chad Granum <[email protected]>.
282 .PP
283 This program is free software; you can redistribute it and/or
284 modify it under the same terms as Perl itself.
285 .PP
286 See \fIhttp://dev.perl.org/licenses/\fR