4 # Time-stamp: "2004-04-28 21:46:51 ADT"
9 use vars (qw($VERSION @ISA @EXPORT @EXPORT_OK $ntest $TestLevel), #public-ish
10 qw($TESTOUT $TESTERR %Program_Lines $told_about_diff
11 $ONFAIL %todo %history $planned @FAILDETAIL) #private-ish
14 # In case a test is run in a persistent environment.
20 $TestLevel = 0; # how many extra stack frames to skip
28 @EXPORT = qw(&plan &ok &skip);
29 @EXPORT_OK = qw($ntest $TESTOUT $TESTERR);
32 $TESTOUT = *STDOUT{IO};
33 $TESTERR = *STDERR{IO};
35 # Use of this variable is strongly discouraged. It is set mainly to
36 # help test coverage analyzers know which test is running.
37 $ENV{REGRESSION_TEST} = $0;
42 Test - provides a simple framework for writing test scripts
49 # use a BEGIN block so we print our plan before MyModule is loaded
50 BEGIN { plan tests => 14, todo => [3,4] }
55 # Helpful notes. All note-lines must start with a "#".
56 print "# I'm testing MyModule version $MyModule::VERSION\n";
61 ok(0); # ok, expected failure (see todo list, above)
62 ok(1); # surprise success!
64 ok(0,1); # failure: '0' ne '1'
65 ok('broke','fixed'); # failure: 'broke' ne 'fixed'
66 ok('fixed','fixed'); # success: 'fixed' eq 'fixed'
67 ok('fixed',qr/x/); # success: 'fixed' =~ qr/x/
69 ok(sub { 1+1 }, 2); # success: '2' eq '2'
70 ok(sub { 1+1 }, 3); # failure: '2' ne '3'
73 ok @list, 3, "\@list=".join(',',@list); #extra notes
74 ok 'segmentation fault', '/(?i)success/'; #regex match
77 $^O =~ m/MSWin/ ? "Skip if MSWin" : 0, # whether to skip
78 $foo, $bar # arguments just like for ok(...)
81 $^O =~ m/MSWin/ ? 0 : "Skip unless MSWin", # whether to skip
82 $foo, $bar # arguments just like for ok(...)
87 This module simplifies the task of writing test files for Perl modules,
88 such that their output is in the format that
89 L<Test::Harness|Test::Harness> expects to see.
91 =head1 QUICK START GUIDE
93 To write a test for your new (and probably not even done) module, create
94 a new file called F<t/test.t> (in a new F<t> directory). If you have
95 multiple test files, to test the "foo", "bar", and "baz" feature sets,
96 then feel free to call your files F<t/foo.t>, F<t/bar.t>, and
101 This module defines three public functions, C<plan(...)>, C<ok(...)>,
102 and C<skip(...)>. By default, all three are exported by
103 the C<use Test;> statement.
109 BEGIN { plan %theplan; }
111 This should be the first thing you call in your test script. It
112 declares your testing plan, how many there will be, if any of them
113 should be allowed to fail, and so on.
115 Typical usage is just:
118 BEGIN { plan tests => 23 }
120 These are the things that you can put in the parameters to plan:
124 =item C<tests =E<gt> I<number>>
126 The number of tests in your script.
127 This means all ok() and skip() calls.
129 =item C<todo =E<gt> [I<1,5,14>]>
131 A reference to a list of tests which are allowed to fail.
134 =item C<onfail =E<gt> sub { ... }>
136 =item C<onfail =E<gt> \&some_sub>
138 A subroutine reference to be run at the end of the test script, if
139 any of the tests fail. See L</ONFAIL>.
143 You must call C<plan(...)> once and only once. You should call it
144 in a C<BEGIN {...}> block, like so:
146 BEGIN { plan tests => 23 }
151 croak "Test::plan(%args): odd number of arguments" if @_ & 1;
152 croak "Test::plan(): should not be called more than once" if $planned;
154 local($\, $,); # guard against -l and other things that screw with
159 _read_program( (caller)[1] );
163 my ($k,$v) = splice(@_, 0, 2);
164 if ($k =~ /^test(s)?$/) { $max = $v; }
165 elsif ($k eq 'todo' or
166 $k eq 'failok') { for (@$v) { $todo{$_}=1; }; }
167 elsif ($k eq 'onfail') {
168 ref $v eq 'CODE' or croak "Test::plan(onfail => $v): must be CODE";
171 else { carp "Test::plan(): skipping unrecognized directive '$k'" }
173 my @todo = sort { $a <=> $b } keys %todo;
175 print $TESTOUT "1..$max todo ".join(' ', @todo).";\n";
177 print $TESTOUT "1..$max\n";
180 print $TESTOUT "# Running under perl version $] for $^O",
181 (chr(65) eq 'A') ? "\n" : " in a non-ASCII world\n";
183 print $TESTOUT "# Win32::BuildNumber ", &Win32::BuildNumber(), "\n"
184 if defined(&Win32::BuildNumber) and defined &Win32::BuildNumber();
186 print $TESTOUT "# MacPerl version $MacPerl::Version\n"
187 if defined $MacPerl::Version;
190 "# Current time local: %s\n# Current time GMT: %s\n",
191 scalar(localtime($^T)), scalar(gmtime($^T));
193 print $TESTOUT "# Using Test.pm version $VERSION\n";
201 return unless defined $file and length $file
202 and -e $file and -f _ and -r _;
203 open(SOURCEFILE, "<$file") || return;
204 $Program_Lines{$file} = [<SOURCEFILE>];
207 foreach my $x (@{$Program_Lines{$file}})
208 { $x =~ tr/\cm\cj\n\r//d }
210 unshift @{$Program_Lines{$file}}, '';
218 my $value = _to_value($input);
220 Converts an C<ok> parameter to its value. Typically this just means
221 running it, if it's a code reference. You should run all inputted
228 return ref $v eq 'CODE' ? $v->() : $v;
233 return "<UNDEF>" unless defined $str;
237 $str =~ s/[\b]/\\b/g;
243 $str =~ s/([\0-\037])(?!\d)/sprintf('\\%o',ord($1))/eg;
244 $str =~ s/([\0-\037\177-\377])/sprintf('\\x%02X',ord($1))/eg;
245 $str =~ s/([^\0-\176])/sprintf('\\x{%X}',ord($1))/eg;
247 # substr( $str , 218-3 ) = "..."
248 # if length($str) >= 218 and !$ENV{PERL_TEST_NO_TRUNC};
260 ok($have, $expect, $diagnostics);
262 This function is the reason for C<Test>'s existence. It's
263 the basic function that
264 handles printing "C<ok>" or "C<not ok>", along with the
265 current test number. (That's what C<Test::Harness> wants to see.)
267 In its most basic usage, C<ok(...)> simply takes a single scalar
268 expression. If its value is true, the test passes; if false,
269 the test fails. Examples:
271 # Examples of ok(scalar)
273 ok( 1 + 1 == 2 ); # ok if 1 + 1 == 2
274 ok( $foo =~ /bar/ ); # ok if $foo contains 'bar'
275 ok( baz($x + $y) eq 'Armondo' ); # ok if baz($x + $y) returns
277 ok( @a == @b ); # ok if @a and @b are the same length
279 The expression is evaluated in scalar context. So the following will
282 ok( @stuff ); # ok if @stuff has any elements
283 ok( !grep !defined $_, @stuff ); # ok if everything in @stuff is
286 A special case is if the expression is a subroutine reference (in either
287 C<sub {...}> syntax or C<\&foo> syntax). In
288 that case, it is executed and its value (true or false) determines if
289 the test passes or fails. For example,
291 ok( sub { # See whether sleep works at least passably
292 my $start_time = time;
294 time() - $start_time >= 4
297 In its two-argument form, C<ok(I<arg1>, I<arg2>)> compares the two
298 scalar values to see if they match. They match if both are undefined,
299 or if I<arg2> is a regex that matches I<arg1>, or if they compare equal
302 # Example of ok(scalar, scalar)
304 ok( "this", "that" ); # not ok, 'this' ne 'that'
305 ok( "", undef ); # not ok, "" is defined
307 The second argument is considered a regex if it is either a regex
308 object or a string that looks like a regex. Regex objects are
309 constructed with the qr// operator in recent versions of perl. A
310 string is considered to look like a regex if its first and last
311 characters are "/", or if the first character is "m"
312 and its second and last characters are both the
313 same non-alphanumeric non-whitespace character. These regexp
317 ok( 'JaffO', '/Jaff/' ); # ok, 'JaffO' =~ /Jaff/
318 ok( 'JaffO', 'm|Jaff|' ); # ok, 'JaffO' =~ m|Jaff|
319 ok( 'JaffO', qr/Jaff/ ); # ok, 'JaffO' =~ qr/Jaff/;
320 ok( 'JaffO', '/(?i)jaff/ ); # ok, 'JaffO' =~ /jaff/i;
322 If either (or both!) is a subroutine reference, it is run and used
323 as the value for comparing. For example:
326 open(OUT, ">x.dat") || die $!;
327 print OUT "\x{e000}";
329 my $bytecount = -s 'x.dat';
330 unlink 'x.dat' or warn "Can't unlink : $!";
336 The above test passes two values to C<ok(arg1, arg2)> -- the first
337 a coderef, and the second is the number 4. Before C<ok> compares them,
338 it calls the coderef, and uses its return value as the real value of
339 this parameter. Assuming that C<$bytecount> returns 4, C<ok> ends up
340 testing C<4 eq 4>. Since that's true, this test passes.
342 Finally, you can append an optional third argument, in
343 C<ok(I<arg1>,I<arg2>, I<note>)>, where I<note> is a string value that
344 will be printed if the test fails. This should be some useful
345 information about the test, pertaining to why it failed, and/or
346 a description of the test. For example:
348 ok( grep($_ eq 'something unique', @stuff), 1,
349 "Something that should be unique isn't!\n".
350 '@stuff = '.join ', ', @stuff
353 Unfortunately, a note cannot be used with the single argument
354 style of C<ok()>. That is, if you try C<ok(I<arg1>, I<note>)>, then
355 C<Test> will interpret this as C<ok(I<arg1>, I<arg2>)>, and probably
356 end up testing C<I<arg1> eq I<arg2>> -- and that's not what you want!
358 All of the above special cases can occasionally cause some
359 problems. See L</BUGS and CAVEATS>.
363 # A past maintainer of this module said:
364 # <<ok(...)'s special handling of subroutine references is an unfortunate
365 # "feature" that can't be removed due to compatibility.>>
369 croak "ok: plan before you test!" if !$planned;
371 local($\,$,); # guard against -l and other things that screw with
374 my ($pkg,$file,$line) = caller($TestLevel);
375 my $repetition = ++$history{"$file:$line"};
376 my $context = ("$file at line $line".
377 ($repetition > 1 ? " fail \#$repetition" : ''));
379 # Are we comparing two values?
383 my $result = _to_value(shift);
384 my ($expected, $isregex, $regex);
389 $expected = _to_value(shift);
390 if (!defined $expected) {
391 $ok = !defined $result;
392 } elsif (!defined $result) {
394 } elsif (ref($expected) eq 'Regexp') {
395 $ok = $result =~ /$expected/;
397 } elsif (($regex) = ($expected =~ m,^ / (.+) / $,sx) or
398 (undef, $regex) = ($expected =~ m,^ m([^\w\s]) (.+) \1 $,sx)) {
399 $ok = $result =~ /$regex/;
401 $ok = $result eq $expected;
404 my $todo = $todo{$ntest};
406 $context .= ' TODO?!' if $todo;
407 print $TESTOUT "ok $ntest # ($context)\n";
409 # Issuing two seperate prints() causes problems on VMS.
411 print $TESTOUT "not ok $ntest\n";
414 print $TESTOUT "ok $ntest\n";
417 $ok or _complain($result, $expected,
419 'repetition' => $repetition, 'package' => $pkg,
420 'result' => $result, 'todo' => $todo,
421 'file' => $file, 'line' => $line,
422 'context' => $context, 'compare' => $compare,
423 @_ ? ('diagnostic' => _to_value(shift)) : (),
433 my($result, $expected, $detail) = @_;
434 $$detail{expected} = $expected if defined $expected;
436 # Get the user's diagnostic, protecting against multi-line
438 my $diag = $$detail{diagnostic};
439 $diag =~ s/\n/\n#/g if defined $diag;
441 $$detail{context} .= ' *TODO*' if $$detail{todo};
442 if (!$$detail{compare}) {
444 print $TESTERR "# Failed test $ntest in $$detail{context}\n";
446 print $TESTERR "# Failed test $ntest in $$detail{context}: $diag\n";
449 my $prefix = "Test $ntest";
451 print $TESTERR "# $prefix got: " . _quote($result) .
452 " ($$detail{context})\n";
453 $prefix = ' ' x (length($prefix) - 5);
454 my $expected_quoted = (defined $$detail{regex})
455 ? 'qr{'.($$detail{regex}).'}' : _quote($expected);
457 print $TESTERR "# $prefix Expected: $expected_quoted",
458 $diag ? " ($diag)" : (), "\n";
460 _diff_complain( $result, $expected, $detail, $prefix )
461 if defined($expected) and 2 < ($expected =~ tr/\n//);
464 if(defined $Program_Lines{ $$detail{file} }[ $$detail{line} ]) {
466 "# $$detail{file} line $$detail{line} is: $Program_Lines{ $$detail{file} }[ $$detail{line} ]\n"
467 if $Program_Lines{ $$detail{file} }[ $$detail{line} ]
468 =~ m/[^\s\#\(\)\{\}\[\]\;]/; # Otherwise it's uninformative
470 undef $Program_Lines{ $$detail{file} }[ $$detail{line} ];
471 # So we won't repeat it.
474 push @FAILDETAIL, $detail;
481 my($result, $expected, $detail, $prefix) = @_;
482 return _diff_complain_external(@_) if $ENV{PERL_TEST_DIFF};
483 return _diff_complain_algdiff(@_)
484 if eval { require Algorithm::Diff; Algorithm::Diff->VERSION(1.15); 1; };
486 $told_about_diff++ or print $TESTERR <<"EOT";
487 # $prefix (Install the Algorithm::Diff module to have differences in multiline
488 # $prefix output explained. You might also set the PERL_TEST_DIFF environment
489 # $prefix variable to run a diff program on the output.)
497 sub _diff_complain_external {
498 my($result, $expected, $detail, $prefix) = @_;
499 my $diff = $ENV{PERL_TEST_DIFF} || die "WHAAAA?";
502 my($got_fh, $got_filename) = File::Temp::tempfile("test-got-XXXXX");
503 my($exp_fh, $exp_filename) = File::Temp::tempfile("test-exp-XXXXX");
504 unless ($got_fh && $exp_fh) {
505 warn "Can't get tempfiles";
509 print $got_fh $result;
510 print $exp_fh $expected;
511 if (close($got_fh) && close($exp_fh)) {
512 my $diff_cmd = "$diff $exp_filename $got_filename";
513 print $TESTERR "#\n# $prefix $diff_cmd\n";
514 if (open(DIFF, "$diff_cmd |")) {
517 print $TESTERR "# $prefix $_";
522 warn "Can't run diff: $!";
525 warn "Can't write to tempfiles: $!";
527 unlink($got_filename);
528 unlink($exp_filename);
534 sub _diff_complain_algdiff {
535 my($result, $expected, $detail, $prefix) = @_;
537 my @got = split(/^/, $result);
538 my @exp = split(/^/, $expected);
543 my $diff_flush = sub {
544 return unless $diff_kind;
546 my $count_lines = @diff_lines;
547 my $s = $count_lines == 1 ? "" : "s";
548 my $first_line = $diff_lines[0][0] + 1;
550 print $TESTERR "# $prefix ";
551 if ($diff_kind eq "GOT") {
552 print $TESTERR "Got $count_lines extra line$s at line $first_line:\n";
553 for my $i (@diff_lines) {
554 print $TESTERR "# $prefix + " . _quote($got[$i->[0]]) . "\n";
556 } elsif ($diff_kind eq "EXP") {
557 if ($count_lines > 1) {
558 my $last_line = $diff_lines[-1][0] + 1;
559 print $TESTERR "Lines $first_line-$last_line are";
562 print $TESTERR "Line $first_line is";
564 print $TESTERR " missing:\n";
565 for my $i (@diff_lines) {
566 print $TESTERR "# $prefix - " . _quote($exp[$i->[1]]) . "\n";
568 } elsif ($diff_kind eq "CH") {
569 if ($count_lines > 1) {
570 my $last_line = $diff_lines[-1][0] + 1;
571 print $TESTERR "Lines $first_line-$last_line are";
574 print $TESTERR "Line $first_line is";
576 print $TESTERR " changed:\n";
577 for my $i (@diff_lines) {
578 print $TESTERR "# $prefix - " . _quote($exp[$i->[1]]) . "\n";
579 print $TESTERR "# $prefix + " . _quote($got[$i->[0]]) . "\n";
588 my $diff_collect = sub {
590 &$diff_flush() if $diff_kind && $diff_kind ne $kind;
592 push(@diff_lines, [@_]);
596 Algorithm::Diff::traverse_balanced(
599 DISCARD_A => sub { &$diff_collect("GOT", @_) },
600 DISCARD_B => sub { &$diff_collect("EXP", @_) },
601 CHANGE => sub { &$diff_collect("CH", @_) },
602 MATCH => sub { &$diff_flush() },
613 #~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~
616 =item C<skip(I<skip_if_true>, I<args...>)>
618 This is used for tests that under some conditions can be skipped. It's
619 basically equivalent to:
621 if( $skip_if_true ) {
627 ...except that the C<ok(1)> emits not just "C<ok I<testnum>>" but
628 actually "C<ok I<testnum> # I<skip_if_true_value>>".
630 The arguments after the I<skip_if_true> are what is fed to C<ok(...)> if
631 this test isn't skipped.
636 $^O =~ m/MSWin/ ? 'Skip if under MSWin' : '';
638 # A test to be skipped if under MSWin (i.e., run except under MSWin)
639 skip($if_MSWin, thing($foo), thing($bar) );
641 Or, going the other way:
644 $^O =~ m/MSWin/ ? '' : 'Skip unless under MSWin';
646 # A test to be skipped unless under MSWin (i.e., run only under MSWin)
647 skip($unless_MSWin, thing($foo), thing($bar) );
649 The tricky thing to remember is that the first parameter is true if
650 you want to I<skip> the test, not I<run> it; and it also doubles as a
651 note about why it's being skipped. So in the first codeblock above, read
652 the code as "skip if MSWin -- (otherwise) test whether C<thing($foo)> is
653 C<thing($bar)>" or for the second case, "skip unless MSWin...".
655 Also, when your I<skip_if_reason> string is true, it really should (for
656 backwards compatibility with older Test.pm versions) start with the
657 string "Skip", as shown in the above examples.
659 Note that in the above cases, C<thing($foo)> and C<thing($bar)>
660 I<are> evaluated -- but as long as the C<skip_if_true> is true,
661 then we C<skip(...)> just tosses out their value (i.e., not
662 bothering to treat them like values to C<ok(...)>. But if
663 you need to I<not> eval the arguments when skipping the
669 # This code returns true if the test passes.
670 # (But it doesn't even get called if the test is skipped.)
671 thing($foo) eq thing($bar)
675 or even this, which is basically equivalent:
678 sub { thing($foo) }, sub { thing($bar) }
681 That is, both are like this:
683 if( $unless_MSWin ) {
684 ok(1); # but it actually appends "# $unless_MSWin"
685 # so that Test::Harness can tell it's a skip
687 # Not skipping, so actually call and evaluate...
688 ok( sub { thing($foo) }, sub { thing($bar) } );
694 local($\, $,); # guard against -l and other things that screw with
697 my $whyskip = _to_value(shift);
698 if (!@_ or $whyskip) {
699 $whyskip = '' if $whyskip =~ m/^\d+$/;
700 $whyskip =~ s/^[Ss]kip(?:\s+|$)//; # backwards compatibility, old
701 # versions required the reason
702 # to start with 'skip'
703 # We print in one shot for VMSy reasons.
704 my $ok = "ok $ntest # skip";
705 $ok .= " $whyskip" if length $whyskip;
711 # backwards compatiblity (I think). skip() used to be
712 # called like ok(), which is weird. I haven't decided what to do with
714 # warn <<WARN if $^W;
715 #This looks like a skip() using the very old interface. Please upgrade to
716 #the documented interface as this has been deprecated.
719 local($TestLevel) = $TestLevel+1; #to ignore this stack frame
729 $ONFAIL->(\@FAILDETAIL) if @FAILDETAIL && $ONFAIL;
741 These tests are expected to succeed. Usually, most or all of your tests
742 are in this category. If a normal test doesn't succeed, then that
743 means that something is I<wrong>.
745 =item * SKIPPED TESTS
747 The C<skip(...)> function is for tests that might or might not be
748 possible to run, depending
749 on the availability of platform-specific features. The first argument
750 should evaluate to true (think "yes, please skip") if the required
751 feature is I<not> available. After the first argument, C<skip(...)> works
752 exactly the same way as C<ok(...)> does.
756 TODO tests are designed for maintaining an B<executable TODO list>.
757 These tests are I<expected to fail.> If a TODO test does succeed,
758 then the feature in question shouldn't be on the TODO list, now
761 Packages should NOT be released with succeeding TODO tests. As soon
762 as a TODO test starts working, it should be promoted to a normal test,
763 and the newly working feature should be documented in the release
764 notes or in the change log.
770 BEGIN { plan test => 4, onfail => sub { warn "CALL 911!" } }
772 Although test failures should be enough, extra diagnostics can be
773 triggered at the end of a test run. C<onfail> is passed an array ref
774 of hash refs that describe each test failure. Each hash will contain
775 at least the following fields: C<package>, C<repetition>, and
776 C<result>. (You shouldn't rely on any other fields being present.) If the test
777 had an expected value or a diagnostic (or "note") string, these will also be
780 The I<optional> C<onfail> hook might be used simply to print out the
781 version of your package and/or how to report problems. It might also
782 be used to generate extremely sophisticated diagnostics for a
783 particularly bizarre test failure. However it's not a panacea. Core
784 dumps or other unrecoverable errors prevent the C<onfail> hook from
785 running. (It is run inside an C<END> block.) Besides, C<onfail> is
786 probably over-kill in most cases. (Your test code should be simpler
787 than the code it is testing, yes?)
790 =head1 BUGS and CAVEATS
796 C<ok(...)>'s special handing of strings which look like they might be
797 regexes can also cause unexpected behavior. An innocent:
799 ok( $fileglob, '/path/to/some/*stuff/' );
801 will fail, since Test.pm considers the second argument to be a regex!
802 The best bet is to use the one-argument form:
804 ok( $fileglob eq '/path/to/some/*stuff/' );
808 C<ok(...)>'s use of string C<eq> can sometimes cause odd problems
810 numbers, especially if you're casting a string to a number:
813 ok( $foo, 1 ); # not ok, "1.0" ne 1
815 Your best bet is to use the single argument form:
817 ok( $foo == 1 ); # ok "1.0" == 1
821 As you may have inferred from the above documentation and examples,
822 C<ok>'s prototype is C<($;$$)> (and, incidentally, C<skip>'s is
823 C<($;$$$)>). This means, for example, that you can do C<ok @foo, @bar>
824 to compare the I<size> of the two arrays. But don't be fooled into
825 thinking that C<ok @foo, @bar> means a comparison of the contents of two
826 arrays -- you're comparing I<just> the number of elements of each. It's
827 so easy to make that mistake in reading C<ok @foo, @bar> that you might
828 want to be very explicit about it, and instead write C<ok scalar(@foo),
833 This almost definitely doesn't do what you expect:
835 ok $thingy->can('some_method');
837 Why? Because C<can> returns a coderef to mean "yes it can (and the
838 method is this...)", and then C<ok> sees a coderef and thinks you're
839 passing a function that you want it to call and consider the truth of
840 the result of! I.e., just like:
842 ok $thingy->can('some_method')->();
844 What you probably want instead is this:
846 ok $thingy->can('some_method') && 1;
848 If the C<can> returns false, then that is passed to C<ok>. If it
849 returns true, then the larger expression S<< C<<
850 $thingy->can('some_method') && 1 >> >> returns 1, which C<ok> sees as
851 a simple signal of success, as you would expect.
856 The syntax for C<skip> is about the only way it can be, but it's still
857 quite confusing. Just start with the above examples and you'll
860 Moreover, users may expect this:
862 skip $unless_mswin, foo($bar), baz($quux);
864 to not evaluate C<foo($bar)> and C<baz($quux)> when the test is being
865 skipped. But in reality, they I<are> evaluated, but C<skip> just won't
866 bother comparing them if C<$unless_mswin> is true.
870 skip $unless_mswin, sub{foo($bar)}, sub{baz($quux)};
872 But that's not terribly pretty. You may find it simpler or clearer in
873 the long run to just do things like this:
875 if( $^O =~ m/MSWin/ ) {
876 print "# Yay, we're under $^O\n";
877 ok foo($bar), baz($quux);
878 ok thing($whatever), baz($stuff);
879 ok blorp($quux, $whatever);
880 ok foo($barzbarz), thang($quux);
882 print "# Feh, we're under $^O. Watch me skip some tests...\n";
883 for(1 .. 4) { skip "Skip unless under MSWin" }
886 But be quite sure that C<ok> is called exactly as many times in the
887 first block as C<skip> is called in the second block.
894 If C<PERL_TEST_DIFF> environment variable is set, it will be used as a
895 command for comparing unexpected multiline results. If you have GNU
896 diff installed, you might want to set C<PERL_TEST_DIFF> to C<diff -u>.
897 If you don't have a suitable program, you might install the
898 C<Text::Diff> module and then set C<PERL_TEST_DIFF> to be C<perl
899 -MText::Diff -e 'print diff(@ARGV)'>. If C<PERL_TEST_DIFF> isn't set
900 but the C<Algorithm::Diff> module is available, then it will be used
901 to show the differences in multiline results.
904 If C<PERL_TEST_NO_TRUNC> is set, then the initial "Got 'something' but
905 expected 'something_else'" readings for long multiline output values aren't
906 truncated at about the 230th column, as they normally could be in some
907 cases. Normally you won't need to use this, unless you were carefully
908 parsing the output of your test programs.
913 A past developer of this module once said that it was no longer being
914 actively developed. However, rumors of its demise were greatly
915 exaggerated. Feedback and suggestions are quite welcome.
917 Be aware that the main value of this module is its simplicity. Note
918 that there are already more ambitious modules out there, such as
919 L<Test::More> and L<Test::Unit>.
921 Some earlier versions of this module had docs with some confusing
922 typoes in the description of C<skip(...)>.
929 L<Test::Simple>, L<Test::More>, L<Devel::Cover>
931 L<Test::Builder> for building your own testing library.
933 L<Test::Unit> is an interesting XUnit-style testing library.
935 L<Test::Inline> and L<SelfTest> let you embed tests in code.
940 Copyright (c) 1998-2000 Joshua Nathaniel Pritikin. All rights reserved.
942 Copyright (c) 2001-2002 Michael G. Schwern.
944 Copyright (c) 2002-2004 and counting Sean M. Burke.
946 Current maintainer: Sean M. Burke. E<lt>sburke@cpan.orgE<gt>
948 This package is free software and is provided "as is" without express
949 or implied warranty. It may be used, redistributed and/or modified
950 under the same terms as Perl itself.
954 # "Your mistake was a hidden intention."
955 # -- /Oblique Strategies/, Brian Eno and Peter Schmidt