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