Debian Codegraph @

upstream/opensuse-tumbleweed/man3/Test.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 3pm"
61 .TH Test 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 \- provides a simple framework for writing test scripts
68 .SH SYNOPSIS
69 .IX Header "SYNOPSIS"
70 .Vb 2
71 \& use strict;
72 \& use Test;
73 \&
74 \& # use a BEGIN block so we print our plan before MyModule is loaded
75 \& BEGIN { plan tests => 14, todo => [3,4] }
76 \&
77 \& # load your module...
78 \& use MyModule;
79 \&
80 \& # Helpful notes. All note\-lines must start with a "#".
81 \& print "# I\*(Aqm testing MyModule version $MyModule::VERSION\en";
82 \&
83 \& ok(0); # failure
84 \& ok(1); # success
85 \&
86 \& ok(0); # ok, expected failure (see todo list, above)
87 \& ok(1); # surprise success!
88 \&
89 \& ok(0,1); # failure: \*(Aq0\*(Aq ne \*(Aq1\*(Aq
90 \& ok(\*(Aqbroke\*(Aq,\*(Aqfixed\*(Aq); # failure: \*(Aqbroke\*(Aq ne \*(Aqfixed\*(Aq
91 \& ok(\*(Aqfixed\*(Aq,\*(Aqfixed\*(Aq); # success: \*(Aqfixed\*(Aq eq \*(Aqfixed\*(Aq
92 \& ok(\*(Aqfixed\*(Aq,qr/x/); # success: \*(Aqfixed\*(Aq =~ qr/x/
93 \&
94 \& ok(sub { 1+1 }, 2); # success: \*(Aq2\*(Aq eq \*(Aq2\*(Aq
95 \& ok(sub { 1+1 }, 3); # failure: \*(Aq2\*(Aq ne \*(Aq3\*(Aq
96 \&
97 \& my @list = (0,0);
98 \& ok @list, 3, "\e@list=".join(\*(Aq,\*(Aq,@list); #extra notes
99 \& ok \*(Aqsegmentation fault\*(Aq, \*(Aq/(?i)success/\*(Aq; #regex match
100 \&
101 \& skip(
102 \& $^O =~ m/MSWin/ ? "Skip if MSWin" : 0, # whether to skip
103 \& $foo, $bar # arguments just like for ok(...)
104 \& );
105 \& skip(
106 \& $^O =~ m/MSWin/ ? 0 : "Skip unless MSWin", # whether to skip
107 \& $foo, $bar # arguments just like for ok(...)
108 \& );
109 .Ve
110 .SH DESCRIPTION
111 .IX Header "DESCRIPTION"
112 This module simplifies the task of writing test files for Perl modules,
113 such that their output is in the format that
114 Test::Harness expects to see.
115 .SH "QUICK START GUIDE"
116 .IX Header "QUICK START GUIDE"
117 To write a test for your new (and probably not even done) module, create
118 a new file called \fIt/test.t\fR (in a new \fIt\fR directory). If you have
119 multiple test files, to test the "foo", "bar", and "baz" feature sets,
120 then feel free to call your files \fIt/foo.t\fR, \fIt/bar.t\fR, and
121 \&\fIt/baz.t\fR
122 .SS Functions
123 .IX Subsection "Functions"
124 This module defines three public functions, \f(CWplan(...)\fR, \f(CWok(...)\fR,
125 and \f(CWskip(...)\fR. By default, all three are exported by
126 the \f(CW\*(C`use Test;\*(C'\fR statement.
127 .ie n .IP plan(...) 4
128 .el .IP \f(CWplan(...)\fR 4
129 .IX Item "plan(...)"
130 .Vb 1
131 \& BEGIN { plan %theplan; }
132 .Ve
133 .Sp
134 This should be the first thing you call in your test script. It
135 declares your testing plan, how many there will be, if any of them
136 should be allowed to fail, and so on.
137 .Sp
138 Typical usage is just:
139 .Sp
140 .Vb 2
141 \& use Test;
142 \& BEGIN { plan tests => 23 }
143 .Ve
144 .Sp
145 These are the things that you can put in the parameters to plan:
146 .RS 4
147 .ie n .IP """tests => \fInumber\fR""" 4
148 .el .IP "\f(CWtests => \fR\f(CInumber\fR\f(CW\fR" 4
149 .IX Item "tests => number"
150 The number of tests in your script.
151 This means all \fBok()\fR and \fBskip()\fR calls.
152 .ie n .IP """todo => [\fI1,5,14\fR]""" 4
153 .el .IP "\f(CWtodo => [\fR\f(CI1,5,14\fR\f(CW]\fR" 4
154 .IX Item "todo => [1,5,14]"
155 A reference to a list of tests which are allowed to fail.
156 See "TODO TESTS".
157 .ie n .IP """onfail => sub { ... }""" 4
158 .el .IP "\f(CWonfail => sub { ... }\fR" 4
159 .IX Item "onfail => sub { ... }"
160 .PD 0
161 .ie n .IP """onfail => \e&some_sub""" 4
162 .el .IP "\f(CWonfail => \e&some_sub\fR" 4
163 .IX Item "onfail => &some_sub"
164 .PD
165 A subroutine reference to be run at the end of the test script, if
166 any of the tests fail. See "ONFAIL".
167 .RE
168 .RS 4
169 .Sp
170 You must call \f(CWplan(...)\fR once and only once. You should call it
171 in a \f(CW\*(C`BEGIN {...}\*(C'\fR block, like so:
172 .Sp
173 .Vb 1
174 \& BEGIN { plan tests => 23 }
175 .Ve
176 .RE
177 .ie n .IP ok(...) 4
178 .el .IP \f(CWok(...)\fR 4
179 .IX Item "ok(...)"
180 .Vb 3
181 \& ok(1 + 1 == 2);
182 \& ok($have, $expect);
183 \& ok($have, $expect, $diagnostics);
184 .Ve
185 .Sp
186 This function is the reason for \f(CW\*(C`Test\*(C'\fR\*(Aqs existence. It\*(Aqs
187 the basic function that
188 handles printing "\f(CW\*(C`ok\*(C'\fR" or "\f(CW\*(C`not ok\*(C'\fR", along with the
189 current test number. (That\*(Aqs what \f(CW\*(C`Test::Harness\*(C'\fR wants to see.)
190 .Sp
191 In its most basic usage, \f(CWok(...)\fR simply takes a single scalar
192 expression. If its value is true, the test passes; if false,
193 the test fails. Examples:
194 .Sp
195 .Vb 1
196 \& # Examples of ok(scalar)
197 \&
198 \& ok( 1 + 1 == 2 ); # ok if 1 + 1 == 2
199 \& ok( $foo =~ /bar/ ); # ok if $foo contains \*(Aqbar\*(Aq
200 \& ok( baz($x + $y) eq \*(AqArmondo\*(Aq ); # ok if baz($x + $y) returns
201 \& # \*(AqArmondo\*(Aq
202 \& ok( @a == @b ); # ok if @a and @b are the same
203 \& # length
204 .Ve
205 .Sp
206 The expression is evaluated in scalar context. So the following will
207 work:
208 .Sp
209 .Vb 4
210 \& ok( @stuff ); # ok if @stuff has any
211 \& # elements
212 \& ok( !grep !defined $_, @stuff ); # ok if everything in @stuff
213 \& # is defined.
214 .Ve
215 .Sp
216 A special case is if the expression is a subroutine reference (in either
217 \&\f(CW\*(C`sub {...}\*(C'\fR syntax or \f(CW\*(C`\e&foo\*(C'\fR syntax). In
218 that case, it is executed and its value (true or false) determines if
219 the test passes or fails. For example,
220 .Sp
221 .Vb 5
222 \& ok( sub { # See whether sleep works at least passably
223 \& my $start_time = time;
224 \& sleep 5;
225 \& time() \- $start_time >= 4
226 \& });
227 .Ve
228 .Sp
229 In its two\-argument form, \f(CW\*(C`ok(\fR\f(CIarg1\fR\f(CW, \fR\f(CIarg2\fR\f(CW)\*(C'\fR compares the two
230 scalar values to see if they match. They match if both are undefined,
231 or if \fIarg2\fR is a regex that matches \fIarg1\fR, or if they compare equal
232 with \f(CW\*(C`eq\*(C'\fR.
233 .Sp
234 .Vb 1
235 \& # Example of ok(scalar, scalar)
236 \&
237 \& ok( "this", "that" ); # not ok, \*(Aqthis\*(Aq ne \*(Aqthat\*(Aq
238 \& ok( "", undef ); # not ok, "" is defined
239 .Ve
240 .Sp
241 The second argument is considered a regex if it is either a regex
242 object or a string that looks like a regex. Regex objects are
243 constructed with the qr// operator in recent versions of perl. A
244 string is considered to look like a regex if its first and last
245 characters are "/", or if the first character is "m"
246 and its second and last characters are both the
247 same non\-alphanumeric non\-whitespace character. These regexp
248 .Sp
249 Regex examples:
250 .Sp
251 .Vb 4
252 \& ok( \*(AqJaffO\*(Aq, \*(Aq/Jaff/\*(Aq ); # ok, \*(AqJaffO\*(Aq =~ /Jaff/
253 \& ok( \*(AqJaffO\*(Aq, \*(Aqm|Jaff|\*(Aq ); # ok, \*(AqJaffO\*(Aq =~ m|Jaff|
254 \& ok( \*(AqJaffO\*(Aq, qr/Jaff/ ); # ok, \*(AqJaffO\*(Aq =~ qr/Jaff/;
255 \& ok( \*(AqJaffO\*(Aq, \*(Aq/(?i)jaff/ ); # ok, \*(AqJaffO\*(Aq =~ /jaff/i;
256 .Ve
257 .Sp
258 If either (or both!) is a subroutine reference, it is run and used
259 as the value for comparing. For example:
260 .Sp
261 .Vb 10
262 \& ok sub {
263 \& open(OUT, \*(Aq>\*(Aq, \*(Aqx.dat\*(Aq) || die $!;
264 \& print OUT "\ex{e000}";
265 \& close OUT;
266 \& my $bytecount = \-s \*(Aqx.dat\*(Aq;
267 \& unlink \*(Aqx.dat\*(Aq or warn "Can\*(Aqt unlink : $!";
268 \& return $bytecount;
269 \& },
270 \& 4
271 \& ;
272 .Ve
273 .Sp
274 The above test passes two values to \f(CW\*(C`ok(arg1, arg2)\*(C'\fR \-\- the first
275 a coderef, and the second is the number 4. Before \f(CW\*(C`ok\*(C'\fR compares them,
276 it calls the coderef, and uses its return value as the real value of
277 this parameter. Assuming that \f(CW$bytecount\fR returns 4, \f(CW\*(C`ok\*(C'\fR ends up
278 testing \f(CW\*(C`4 eq 4\*(C'\fR. Since that\*(Aqs true, this test passes.
279 .Sp
280 Finally, you can append an optional third argument, in
281 \&\f(CW\*(C`ok(\fR\f(CIarg1\fR\f(CW,\fR\f(CIarg2\fR\f(CW, \fR\f(CInote\fR\f(CW)\*(C'\fR, where \fInote\fR is a string value that
282 will be printed if the test fails. This should be some useful
283 information about the test, pertaining to why it failed, and/or
284 a description of the test. For example:
285 .Sp
286 .Vb 4
287 \& ok( grep($_ eq \*(Aqsomething unique\*(Aq, @stuff), 1,
288 \& "Something that should be unique isn\*(Aqt!\en".
289 \& \*(Aq@stuff = \*(Aq.join \*(Aq, \*(Aq, @stuff
290 \& );
291 .Ve
292 .Sp
293 Unfortunately, a note cannot be used with the single argument
294 style of \f(CWok()\fR. That is, if you try \f(CW\*(C`ok(\fR\f(CIarg1\fR\f(CW, \fR\f(CInote\fR\f(CW)\*(C'\fR, then
295 \&\f(CW\*(C`Test\*(C'\fR will interpret this as \f(CW\*(C`ok(\fR\f(CIarg1\fR\f(CW, \fR\f(CIarg2\fR\f(CW)\*(C'\fR, and probably
296 end up testing \f(CW\*(C`\fR\f(CIarg1\fR\f(CW eq \fR\f(CIarg2\fR\f(CW\*(C'\fR \-\- and that\*(Aqs not what you want!
297 .Sp
298 All of the above special cases can occasionally cause some
299 problems. See "BUGS and CAVEATS".
300 .ie n .IP """skip(\fIskip_if_true\fR, \fIargs...\fR)""" 4
301 .el .IP "\f(CWskip(\fR\f(CIskip_if_true\fR\f(CW, \fR\f(CIargs...\fR\f(CW)\fR" 4
302 .IX Item "skip(skip_if_true, args...)"
303 This is used for tests that under some conditions can be skipped. It\*(Aqs
304 basically equivalent to:
305 .Sp
306 .Vb 5
307 \& if( $skip_if_true ) {
308 \& ok(1);
309 \& } else {
310 \& ok( args... );
311 \& }
312 .Ve
313 .Sp
314 \&...except that the \f(CWok(1)\fR emits not just "\f(CW\*(C`ok \fR\f(CItestnum\fR\f(CW\*(C'\fR" but
315 actually "\f(CW\*(C`ok \fR\f(CItestnum\fR\f(CW # \fR\f(CIskip_if_true_value\fR\f(CW\*(C'\fR".
316 .Sp
317 The arguments after the \fIskip_if_true\fR are what is fed to \f(CWok(...)\fR if
318 this test isn\*(Aqt skipped.
319 .Sp
320 Example usage:
321 .Sp
322 .Vb 2
323 \& my $if_MSWin =
324 \& $^O =~ m/MSWin/ ? \*(AqSkip if under MSWin\*(Aq : \*(Aq\*(Aq;
325 \&
326 \& # A test to be skipped if under MSWin (i.e., run except under
327 \& # MSWin)
328 \& skip($if_MSWin, thing($foo), thing($bar) );
329 .Ve
330 .Sp
331 Or, going the other way:
332 .Sp
333 .Vb 2
334 \& my $unless_MSWin =
335 \& $^O =~ m/MSWin/ ? \*(Aq\*(Aq : \*(AqSkip unless under MSWin\*(Aq;
336 \&
337 \& # A test to be skipped unless under MSWin (i.e., run only under
338 \& # MSWin)
339 \& skip($unless_MSWin, thing($foo), thing($bar) );
340 .Ve
341 .Sp
342 The tricky thing to remember is that the first parameter is true if
343 you want to \fIskip\fR the test, not \fIrun\fR it; and it also doubles as a
344 note about why it\*(Aqs being skipped. So in the first codeblock above, read
345 the code as "skip if MSWin \-\- (otherwise) test whether \f(CWthing($foo)\fR is
346 \&\f(CWthing($bar)\fR" or for the second case, "skip unless MSWin...".
347 .Sp
348 Also, when your \fIskip_if_reason\fR string is true, it really should (for
349 backwards compatibility with older Test.pm versions) start with the
350 string "Skip", as shown in the above examples.
351 .Sp
352 Note that in the above cases, \f(CWthing($foo)\fR and \f(CWthing($bar)\fR
353 \&\fIare\fR evaluated \-\- but as long as the \f(CW\*(C`skip_if_true\*(C'\fR is true,
354 then we \f(CWskip(...)\fR just tosses out their value (i.e., not
355 bothering to treat them like values to \f(CWok(...)\fR. But if
356 you need to \fInot\fR eval the arguments when skipping the
357 test, use
358 this format:
359 .Sp
360 .Vb 7
361 \& skip( $unless_MSWin,
362 \& sub {
363 \& # This code returns true if the test passes.
364 \& # (But it doesn\*(Aqt even get called if the test is skipped.)
365 \& thing($foo) eq thing($bar)
366 \& }
367 \& );
368 .Ve
369 .Sp
370 or even this, which is basically equivalent:
371 .Sp
372 .Vb 3
373 \& skip( $unless_MSWin,
374 \& sub { thing($foo) }, sub { thing($bar) }
375 \& );
376 .Ve
377 .Sp
378 That is, both are like this:
379 .Sp
380 .Vb 7
381 \& if( $unless_MSWin ) {
382 \& ok(1); # but it actually appends "# $unless_MSWin"
383 \& # so that Test::Harness can tell it\*(Aqs a skip
384 \& } else {
385 \& # Not skipping, so actually call and evaluate...
386 \& ok( sub { thing($foo) }, sub { thing($bar) } );
387 \& }
388 .Ve
389 .SH "TEST TYPES"
390 .IX Header "TEST TYPES"
391 .IP \(bu 4
392 NORMAL TESTS
393 .Sp
394 These tests are expected to succeed. Usually, most or all of your tests
395 are in this category. If a normal test doesn\*(Aqt succeed, then that
396 means that something is \fIwrong\fR.
397 .IP \(bu 4
398 SKIPPED TESTS
399 .Sp
400 The \f(CWskip(...)\fR function is for tests that might or might not be
401 possible to run, depending
402 on the availability of platform\-specific features. The first argument
403 should evaluate to true (think "yes, please skip") if the required
404 feature is \fInot\fR available. After the first argument, \f(CWskip(...)\fR works
405 exactly the same way as \f(CWok(...)\fR does.
406 .IP \(bu 4
407 TODO TESTS
408 .Sp
409 TODO tests are designed for maintaining an \fBexecutable TODO list\fR.
410 These tests are \fIexpected to fail.\fR If a TODO test does succeed,
411 then the feature in question shouldn\*(Aqt be on the TODO list, now
412 should it?
413 .Sp
414 Packages should NOT be released with succeeding TODO tests. As soon
415 as a TODO test starts working, it should be promoted to a normal test,
416 and the newly working feature should be documented in the release
417 notes or in the change log.
418 .SH ONFAIL
419 .IX Header "ONFAIL"
420 .Vb 1
421 \& BEGIN { plan test => 4, onfail => sub { warn "CALL 911!" } }
422 .Ve
423 .PP
424 Although test failures should be enough, extra diagnostics can be
425 triggered at the end of a test run. \f(CW\*(C`onfail\*(C'\fR is passed an array ref
426 of hash refs that describe each test failure. Each hash will contain
427 at least the following fields: \f(CW\*(C`package\*(C'\fR, \f(CW\*(C`repetition\*(C'\fR, and
428 \&\f(CW\*(C`result\*(C'\fR. (You shouldn\*(Aqt rely on any other fields being present.) If the test
429 had an expected value or a diagnostic (or "note") string, these will also be
430 included.
431 .PP
432 The \fIoptional\fR \f(CW\*(C`onfail\*(C'\fR hook might be used simply to print out the
433 version of your package and/or how to report problems. It might also
434 be used to generate extremely sophisticated diagnostics for a
435 particularly bizarre test failure. However it\*(Aqs not a panacea. Core
436 dumps or other unrecoverable errors prevent the \f(CW\*(C`onfail\*(C'\fR hook from
437 running. (It is run inside an \f(CW\*(C`END\*(C'\fR block.) Besides, \f(CW\*(C`onfail\*(C'\fR is
438 probably over\-kill in most cases. (Your test code should be simpler
439 than the code it is testing, yes?)
440 .SH "BUGS and CAVEATS"
441 .IX Header "BUGS and CAVEATS"
442 .IP \(bu 4
443 \&\f(CWok(...)\fR\*(Aqs special handing of strings which look like they might be
444 regexes can also cause unexpected behavior. An innocent:
445 .Sp
446 .Vb 1
447 \& ok( $fileglob, \*(Aq/path/to/some/*stuff/\*(Aq );
448 .Ve
449 .Sp
450 will fail, since Test.pm considers the second argument to be a regex!
451 The best bet is to use the one\-argument form:
452 .Sp
453 .Vb 1
454 \& ok( $fileglob eq \*(Aq/path/to/some/*stuff/\*(Aq );
455 .Ve
456 .IP \(bu 4
457 \&\f(CWok(...)\fR\*(Aqs use of string \f(CW\*(C`eq\*(C'\fR can sometimes cause odd problems
458 when comparing
459 numbers, especially if you\*(Aqre casting a string to a number:
460 .Sp
461 .Vb 2
462 \& $foo = "1.0";
463 \& ok( $foo, 1 ); # not ok, "1.0" ne 1
464 .Ve
465 .Sp
466 Your best bet is to use the single argument form:
467 .Sp
468 .Vb 1
469 \& ok( $foo == 1 ); # ok "1.0" == 1
470 .Ve
471 .IP \(bu 4
472 As you may have inferred from the above documentation and examples,
473 \&\f(CW\*(C`ok\*(C'\fR\*(Aqs prototype is \f(CW\*(C`($;$$)\*(C'\fR (and, incidentally, \f(CW\*(C`skip\*(C'\fR\*(Aqs is
474 \&\f(CW\*(C`($;$$$)\*(C'\fR). This means, for example, that you can do \f(CW\*(C`ok @foo, @bar\*(C'\fR
475 to compare the \fIsize\fR of the two arrays. But don\*(Aqt be fooled into
476 thinking that \f(CW\*(C`ok @foo, @bar\*(C'\fR means a comparison of the contents of two
477 arrays \-\- you\*(Aqre comparing \fIjust\fR the number of elements of each. It\*(Aqs
478 so easy to make that mistake in reading \f(CW\*(C`ok @foo, @bar\*(C'\fR that you might
479 want to be very explicit about it, and instead write \f(CWok scalar(@foo),
480 scalar(@bar)\fR.
481 .IP \(bu 4
482 This almost definitely doesn\*(Aqt do what you expect:
483 .Sp
484 .Vb 1
485 \& ok $thingy\->can(\*(Aqsome_method\*(Aq);
486 .Ve
487 .Sp
488 Why? Because \f(CW\*(C`can\*(C'\fR returns a coderef to mean "yes it can (and the
489 method is this...)", and then \f(CW\*(C`ok\*(C'\fR sees a coderef and thinks you\*(Aqre
490 passing a function that you want it to call and consider the truth of
491 the result of! I.e., just like:
492 .Sp
493 .Vb 1
494 \& ok $thingy\->can(\*(Aqsome_method\*(Aq)\->();
495 .Ve
496 .Sp
497 What you probably want instead is this:
498 .Sp
499 .Vb 1
500 \& ok $thingy\->can(\*(Aqsome_method\*(Aq) && 1;
501 .Ve
502 .Sp
503 If the \f(CW\*(C`can\*(C'\fR returns false, then that is passed to \f(CW\*(C`ok\*(C'\fR. If it
504 returns true, then the larger expression \f(CW\*(C`$thingy\->can(\*(Aqsome_method\*(Aq)\ &&\ 1\*(C'\fR returns 1, which \f(CW\*(C`ok\*(C'\fR sees as
505 a simple signal of success, as you would expect.
506 .IP \(bu 4
507 The syntax for \f(CW\*(C`skip\*(C'\fR is about the only way it can be, but it\*(Aqs still
508 quite confusing. Just start with the above examples and you\*(Aqll
509 be okay.
510 .Sp
511 Moreover, users may expect this:
512 .Sp
513 .Vb 1
514 \& skip $unless_mswin, foo($bar), baz($quux);
515 .Ve
516 .Sp
517 to not evaluate \f(CWfoo($bar)\fR and \f(CWbaz($quux)\fR when the test is being
518 skipped. But in reality, they \fIare\fR evaluated, but \f(CW\*(C`skip\*(C'\fR just won\*(Aqt
519 bother comparing them if \f(CW$unless_mswin\fR is true.
520 .Sp
521 You could do this:
522 .Sp
523 .Vb 1
524 \& skip $unless_mswin, sub{foo($bar)}, sub{baz($quux)};
525 .Ve
526 .Sp
527 But that\*(Aqs not terribly pretty. You may find it simpler or clearer in
528 the long run to just do things like this:
529 .Sp
530 .Vb 10
531 \& if( $^O =~ m/MSWin/ ) {
532 \& print "# Yay, we\*(Aqre under $^O\en";
533 \& ok foo($bar), baz($quux);
534 \& ok thing($whatever), baz($stuff);
535 \& ok blorp($quux, $whatever);
536 \& ok foo($barzbarz), thang($quux);
537 \& } else {
538 \& print "# Feh, we\*(Aqre under $^O. Watch me skip some tests...\en";
539 \& for(1 .. 4) { skip "Skip unless under MSWin" }
540 \& }
541 .Ve
542 .Sp
543 But be quite sure that \f(CW\*(C`ok\*(C'\fR is called exactly as many times in the
544 first block as \f(CW\*(C`skip\*(C'\fR is called in the second block.
545 .SH ENVIRONMENT
546 .IX Header "ENVIRONMENT"
547 If \f(CW\*(C`PERL_TEST_DIFF\*(C'\fR environment variable is set, it will be used as a
548 command for comparing unexpected multiline results. If you have GNU
549 diff installed, you might want to set \f(CW\*(C`PERL_TEST_DIFF\*(C'\fR to \f(CW\*(C`diff \-u\*(C'\fR.
550 If you don\*(Aqt have a suitable program, you might install the
551 \&\f(CW\*(C`Text::Diff\*(C'\fR module and then set \f(CW\*(C`PERL_TEST_DIFF\*(C'\fR to be \f(CW\*(C`perl
552 \&\-MText::Diff \-e \*(Aqprint diff(@ARGV)\*(Aq\*(C'\fR. If \f(CW\*(C`PERL_TEST_DIFF\*(C'\fR isn\*(Aqt set
553 but the \f(CW\*(C`Algorithm::Diff\*(C'\fR module is available, then it will be used
554 to show the differences in multiline results.
555 .SH NOTE
556 .IX Header "NOTE"
557 A past developer of this module once said that it was no longer being
558 actively developed. However, rumors of its demise were greatly
559 exaggerated. Feedback and suggestions are quite welcome.
560 .PP
561 Be aware that the main value of this module is its simplicity. Note
562 that there are already more ambitious modules out there, such as
563 Test::More and Test::Unit.
564 .PP
565 Some earlier versions of this module had docs with some confusing
566 typos in the description of \f(CWskip(...)\fR.
567 .SH "SEE ALSO"
568 .IX Header "SEE ALSO"
569 Test::Harness
570 .PP
571 Test::Simple, Test::More, Devel::Cover
572 .PP
573 Test::Builder for building your own testing library.
574 .PP
575 Test::Unit is an interesting XUnit\-style testing library.
576 .PP
577 Test::Inline lets you embed tests in code.
578 .SH AUTHOR
579 .IX Header "AUTHOR"
580 Copyright (c) 1998\-2000 Joshua Nathaniel Pritikin.
581 .PP
582 Copyright (c) 2001\-2002 Michael G. Schwern.
583 .PP
584 Copyright (c) 2002\-2004 Sean M. Burke.
585 .PP
586 Current maintainer: Jesse Vincent. <[email protected]>
587 .PP
588 This package is free software and is provided "as is" without express
589 or implied warranty. It may be used, redistributed and/or modified
590 under the same terms as Perl itself.