Missed files in upgrading modules. Grrrr
[p5sagit/p5-mst-13.2.git] / lib / Test / More.pm
CommitLineData
3f2ec160 1package Test::More;
2
d020a79a 3use 5.004;
3f2ec160 4
d020a79a 5use strict;
3f2ec160 6
33459055 7
8# Can't use Carp because it might cause use_ok() to accidentally succeed
9# even though the module being used forgot to use Carp. Yes, this
10# actually happened.
11sub _carp {
12 my($file, $line) = (caller(1))[1,2];
a9153838 13 warn @_, " at $file line $line\n";
3f2ec160 14}
15
33459055 16
17
33459055 18use vars qw($VERSION @ISA @EXPORT %EXPORT_TAGS $TODO);
b1ddf169 19$VERSION = '0.61';
7483b81c 20$VERSION = eval $VERSION; # make the alpha version come out as a number
21
b1ddf169 22use Test::Builder::Module;
23@ISA = qw(Test::Builder::Module);
3f2ec160 24@EXPORT = qw(ok use_ok require_ok
a9153838 25 is isnt like unlike is_deeply
26 cmp_ok
27 skip todo todo_skip
3f2ec160 28 pass fail
de2dd90a 29 eq_array eq_hash eq_set
d020a79a 30 $TODO
31 plan
32 can_ok isa_ok
a9153838 33 diag
b1ddf169 34 BAIL_OUT
3f2ec160 35 );
36
3f2ec160 37
38=head1 NAME
39
40Test::More - yet another framework for writing test scripts
41
42=head1 SYNOPSIS
43
44 use Test::More tests => $Num_Tests;
45 # or
46 use Test::More qw(no_plan);
47 # or
d020a79a 48 use Test::More skip_all => $reason;
3f2ec160 49
50 BEGIN { use_ok( 'Some::Module' ); }
51 require_ok( 'Some::Module' );
52
53 # Various ways to say "ok"
54 ok($this eq $that, $test_name);
55
56 is ($this, $that, $test_name);
57 isnt($this, $that, $test_name);
a9153838 58
59 # Rather than print STDERR "# here's what went wrong\n"
60 diag("here's what went wrong");
61
62 like ($this, qr/that/, $test_name);
63 unlike($this, qr/that/, $test_name);
64
65 cmp_ok($this, '==', $that, $test_name);
3f2ec160 66
33459055 67 is_deeply($complex_structure1, $complex_structure2, $test_name);
68
d020a79a 69 SKIP: {
70 skip $why, $how_many unless $have_some_feature;
71
3f2ec160 72 ok( foo(), $test_name );
73 is( foo(42), 23, $test_name );
d020a79a 74 };
75
76 TODO: {
77 local $TODO = $why;
3f2ec160 78
3f2ec160 79 ok( foo(), $test_name );
80 is( foo(42), 23, $test_name );
d020a79a 81 };
82
83 can_ok($module, @methods);
84 isa_ok($object, $class);
3f2ec160 85
86 pass($test_name);
87 fail($test_name);
88
b1ddf169 89 BAIL_OUT($why);
3f2ec160 90
d020a79a 91 # UNIMPLEMENTED!!!
b1ddf169 92 my @status = Test::More::status;
d020a79a 93
3f2ec160 94
95=head1 DESCRIPTION
96
a9153838 97B<STOP!> If you're just getting started writing tests, have a look at
d020a79a 98Test::Simple first. This is a drop in replacement for Test::Simple
99which you can switch to once you get the hang of basic testing.
3f2ec160 100
a9153838 101The purpose of this module is to provide a wide range of testing
102utilities. Various ways to say "ok" with better diagnostics,
103facilities to skip tests, test future features and compare complicated
104data structures. While you can do almost anything with a simple
105C<ok()> function, it doesn't provide good diagnostic output.
3f2ec160 106
107
108=head2 I love it when a plan comes together
109
110Before anything else, you need a testing plan. This basically declares
111how many tests your script is going to run to protect against premature
112failure.
113
4bd4e70a 114The preferred way to do this is to declare a plan when you C<use Test::More>.
3f2ec160 115
116 use Test::More tests => $Num_Tests;
117
118There are rare cases when you will not know beforehand how many tests
119your script is going to run. In this case, you can declare that you
120have no plan. (Try to avoid using this as it weakens your test.)
121
122 use Test::More qw(no_plan);
123
30e302f8 124B<NOTE>: using no_plan requires a Test::Harness upgrade else it will
b1ddf169 125think everything has failed. See L<CAVEATS and NOTES>).
30e302f8 126
3f2ec160 127In some cases, you'll want to completely skip an entire testing script.
128
d020a79a 129 use Test::More skip_all => $skip_reason;
3f2ec160 130
d020a79a 131Your script will declare a skip with the reason why you skipped and
132exit immediately with a zero (success). See L<Test::Harness> for
133details.
3f2ec160 134
33459055 135If you want to control what functions Test::More will export, you
136have to use the 'import' option. For example, to import everything
137but 'fail', you'd do:
138
139 use Test::More tests => 23, import => ['!fail'];
140
141Alternatively, you can use the plan() function. Useful for when you
142have to calculate the number of tests.
143
144 use Test::More;
145 plan tests => keys %Stuff * 3;
146
147or for deciding between running the tests at all:
148
149 use Test::More;
150 if( $^O eq 'MacOS' ) {
4bd4e70a 151 plan skip_all => 'Test irrelevant on MacOS';
33459055 152 }
153 else {
154 plan tests => 42;
155 }
156
157=cut
158
159sub plan {
b1ddf169 160 my $tb = Test::More->builder;
7483b81c 161
b1ddf169 162 $tb->plan(@_);
33459055 163}
164
7483b81c 165
b1ddf169 166# This implements "use Test::More 'no_diag'" but the behavior is
167# deprecated.
168sub import_extra {
169 my $class = shift;
170 my $list = shift;
7483b81c 171
b1ddf169 172 my @other = ();
7483b81c 173 my $idx = 0;
b1ddf169 174 while( $idx <= $#{$list} ) {
175 my $item = $list->[$idx];
176
177 if( defined $item and $item eq 'no_diag' ) {
178 $class->builder->no_diag(1);
7483b81c 179 }
180 else {
b1ddf169 181 push @other, $item;
7483b81c 182 }
183
184 $idx++;
185 }
186
b1ddf169 187 @$list = @other;
33459055 188}
189
3f2ec160 190
191=head2 Test names
192
193By convention, each test is assigned a number in order. This is
6686786d 194largely done automatically for you. However, it's often very useful to
3f2ec160 195assign a name to each test. Which would you rather see:
196
197 ok 4
198 not ok 5
199 ok 6
200
201or
202
203 ok 4 - basic multi-variable
204 not ok 5 - simple exponential
205 ok 6 - force == mass * acceleration
206
207The later gives you some idea of what failed. It also makes it easier
208to find the test in your script, simply search for "simple
209exponential".
210
6686786d 211All test functions take a name argument. It's optional, but highly
3f2ec160 212suggested that you use it.
213
214
215=head2 I'm ok, you're not ok.
216
217The basic purpose of this module is to print out either "ok #" or "not
218ok #" depending on if a given test succeeded or failed. Everything
219else is just gravy.
220
221All of the following print "ok" or "not ok" depending on if the test
222succeeded or failed. They all also return true or false,
223respectively.
224
225=over 4
226
227=item B<ok>
228
229 ok($this eq $that, $test_name);
230
231This simply evaluates any expression (C<$this eq $that> is just a
232simple example) and uses that to determine if the test succeeded or
233failed. A true expression passes, a false one fails. Very simple.
234
235For example:
236
237 ok( $exp{9} == 81, 'simple exponential' );
238 ok( Film->can('db_Main'), 'set_db()' );
239 ok( $p->tests == 4, 'saw tests' );
240 ok( !grep !defined $_, @items, 'items populated' );
241
242(Mnemonic: "This is ok.")
243
244$test_name is a very short description of the test that will be printed
245out. It makes it very easy to find a test in your script when it fails
246and gives others an idea of your intentions. $test_name is optional,
247but we B<very> strongly encourage its use.
248
249Should an ok() fail, it will produce some diagnostics:
250
251 not ok 18 - sufficient mucus
b1ddf169 252 # Failed test 'sufficient mucus'
253 # in foo.t at line 42.
3f2ec160 254
255This is actually Test::Simple's ok() routine.
256
257=cut
258
33459055 259sub ok ($;$) {
260 my($test, $name) = @_;
b1ddf169 261 my $tb = Test::More->builder;
262
263 $tb->ok($test, $name);
33459055 264}
3f2ec160 265
266=item B<is>
267
268=item B<isnt>
269
270 is ( $this, $that, $test_name );
271 isnt( $this, $that, $test_name );
272
d020a79a 273Similar to ok(), is() and isnt() compare their two arguments
274with C<eq> and C<ne> respectively and use the result of that to
275determine if the test succeeded or failed. So these:
3f2ec160 276
277 # Is the ultimate answer 42?
278 is( ultimate_answer(), 42, "Meaning of Life" );
279
280 # $foo isn't empty
281 isnt( $foo, '', "Got some foo" );
282
283are similar to these:
284
285 ok( ultimate_answer() eq 42, "Meaning of Life" );
286 ok( $foo ne '', "Got some foo" );
287
288(Mnemonic: "This is that." "This isn't that.")
289
290So why use these? They produce better diagnostics on failure. ok()
291cannot know what you are testing for (beyond the name), but is() and
292isnt() know what the test was and why it failed. For example this
d020a79a 293test:
3f2ec160 294
295 my $foo = 'waffle'; my $bar = 'yarblokos';
296 is( $foo, $bar, 'Is foo the same as bar?' );
297
298Will produce something like this:
299
300 not ok 17 - Is foo the same as bar?
b1ddf169 301 # Failed test 'Is foo the same as bar?'
302 # in foo.t at line 139.
3f2ec160 303 # got: 'waffle'
304 # expected: 'yarblokos'
305
306So you can figure out what went wrong without rerunning the test.
307
308You are encouraged to use is() and isnt() over ok() where possible,
309however do not be tempted to use them to find out if something is
310true or false!
311
30e302f8 312 # XXX BAD!
313 is( exists $brooklyn{tree}, 1, 'A tree grows in Brooklyn' );
3f2ec160 314
30e302f8 315This does not check if C<exists $brooklyn{tree}> is true, it checks if
3f2ec160 316it returns 1. Very different. Similar caveats exist for false and 0.
317In these cases, use ok().
318
30e302f8 319 ok( exists $brooklyn{tree}, 'A tree grows in Brooklyn' );
3f2ec160 320
d020a79a 321For those grammatical pedants out there, there's an C<isn't()>
322function which is an alias of isnt().
3f2ec160 323
324=cut
325
326sub is ($$;$) {
b1ddf169 327 my $tb = Test::More->builder;
328
329 $tb->is_eq(@_);
3f2ec160 330}
331
332sub isnt ($$;$) {
b1ddf169 333 my $tb = Test::More->builder;
334
335 $tb->isnt_eq(@_);
3f2ec160 336}
337
338*isn't = \&isnt;
339
340
341=item B<like>
342
343 like( $this, qr/that/, $test_name );
344
345Similar to ok(), like() matches $this against the regex C<qr/that/>.
346
347So this:
348
349 like($this, qr/that/, 'this is like that');
350
351is similar to:
352
353 ok( $this =~ /that/, 'this is like that');
354
355(Mnemonic "This is like that".)
356
357The second argument is a regular expression. It may be given as a
4bd4e70a 358regex reference (i.e. C<qr//>) or (for better compatibility with older
3f2ec160 359perls) as a string that looks like a regex (alternative delimiters are
360currently not supported):
361
362 like( $this, '/that/', 'this is like that' );
363
364Regex options may be placed on the end (C<'/that/i'>).
365
366Its advantages over ok() are similar to that of is() and isnt(). Better
367diagnostics on failure.
368
369=cut
370
371sub like ($$;$) {
b1ddf169 372 my $tb = Test::More->builder;
373
374 $tb->like(@_);
3f2ec160 375}
376
a9153838 377
378=item B<unlike>
379
380 unlike( $this, qr/that/, $test_name );
381
382Works exactly as like(), only it checks if $this B<does not> match the
383given pattern.
384
385=cut
386
30e302f8 387sub unlike ($$;$) {
b1ddf169 388 my $tb = Test::More->builder;
389
390 $tb->unlike(@_);
a9153838 391}
392
393
394=item B<cmp_ok>
395
396 cmp_ok( $this, $op, $that, $test_name );
397
398Halfway between ok() and is() lies cmp_ok(). This allows you to
399compare two arguments using any binary perl operator.
400
401 # ok( $this eq $that );
402 cmp_ok( $this, 'eq', $that, 'this eq that' );
403
404 # ok( $this == $that );
405 cmp_ok( $this, '==', $that, 'this == that' );
406
407 # ok( $this && $that );
30e302f8 408 cmp_ok( $this, '&&', $that, 'this && that' );
a9153838 409 ...etc...
410
411Its advantage over ok() is when the test fails you'll know what $this
412and $that were:
413
414 not ok 1
b1ddf169 415 # Failed test in foo.t at line 12.
a9153838 416 # '23'
417 # &&
418 # undef
419
6686786d 420It's also useful in those cases where you are comparing numbers and
a9153838 421is()'s use of C<eq> will interfere:
422
423 cmp_ok( $big_hairy_number, '==', $another_big_hairy_number );
424
425=cut
426
427sub cmp_ok($$$;$) {
b1ddf169 428 my $tb = Test::More->builder;
429
430 $tb->cmp_ok(@_);
a9153838 431}
432
433
d020a79a 434=item B<can_ok>
435
436 can_ok($module, @methods);
437 can_ok($object, @methods);
438
439Checks to make sure the $module or $object can do these @methods
440(works with functions, too).
441
442 can_ok('Foo', qw(this that whatever));
443
444is almost exactly like saying:
445
446 ok( Foo->can('this') &&
447 Foo->can('that') &&
448 Foo->can('whatever')
449 );
450
451only without all the typing and with a better interface. Handy for
452quickly testing an interface.
453
a9153838 454No matter how many @methods you check, a single can_ok() call counts
455as one test. If you desire otherwise, use:
456
457 foreach my $meth (@methods) {
458 can_ok('Foo', $meth);
459 }
460
d020a79a 461=cut
462
463sub can_ok ($@) {
464 my($proto, @methods) = @_;
89c1e84a 465 my $class = ref $proto || $proto;
b1ddf169 466 my $tb = Test::More->builder;
d020a79a 467
a9153838 468 unless( @methods ) {
b1ddf169 469 my $ok = $tb->ok( 0, "$class->can(...)" );
470 $tb->diag(' can_ok() called with no methods');
a9153838 471 return $ok;
472 }
473
d020a79a 474 my @nok = ();
475 foreach my $method (@methods) {
a9153838 476 local($!, $@); # don't interfere with caller's $@
477 # eval sometimes resets $!
89c1e84a 478 eval { $proto->can($method) } || push @nok, $method;
d020a79a 479 }
480
481 my $name;
6686786d 482 $name = @methods == 1 ? "$class->can('$methods[0]')"
d020a79a 483 : "$class->can(...)";
484
b1ddf169 485 my $ok = $tb->ok( !@nok, $name );
d020a79a 486
b1ddf169 487 $tb->diag(map " $class->can('$_') failed\n", @nok);
d020a79a 488
33459055 489 return $ok;
d020a79a 490}
491
492=item B<isa_ok>
493
33459055 494 isa_ok($object, $class, $object_name);
a9153838 495 isa_ok($ref, $type, $ref_name);
d020a79a 496
30e302f8 497Checks to see if the given C<< $object->isa($class) >>. Also checks to make
d020a79a 498sure the object was defined in the first place. Handy for this sort
499of thing:
500
501 my $obj = Some::Module->new;
502 isa_ok( $obj, 'Some::Module' );
503
504where you'd otherwise have to write
505
506 my $obj = Some::Module->new;
507 ok( defined $obj && $obj->isa('Some::Module') );
508
509to safeguard against your test script blowing up.
510
a9153838 511It works on references, too:
512
513 isa_ok( $array_ref, 'ARRAY' );
514
33459055 515The diagnostics of this test normally just refer to 'the object'. If
516you'd like them to be more specific, you can supply an $object_name
517(for example 'Test customer').
518
d020a79a 519=cut
520
33459055 521sub isa_ok ($$;$) {
522 my($object, $class, $obj_name) = @_;
b1ddf169 523 my $tb = Test::More->builder;
d020a79a 524
525 my $diag;
33459055 526 $obj_name = 'The object' unless defined $obj_name;
527 my $name = "$obj_name isa $class";
d020a79a 528 if( !defined $object ) {
33459055 529 $diag = "$obj_name isn't defined";
d020a79a 530 }
531 elsif( !ref $object ) {
33459055 532 $diag = "$obj_name isn't a reference";
d020a79a 533 }
a9153838 534 else {
535 # We can't use UNIVERSAL::isa because we want to honor isa() overrides
536 local($@, $!); # eval sometimes resets $!
537 my $rslt = eval { $object->isa($class) };
538 if( $@ ) {
539 if( $@ =~ /^Can't call method "isa" on unblessed reference/ ) {
540 if( !UNIVERSAL::isa($object, $class) ) {
541 my $ref = ref $object;
6686786d 542 $diag = "$obj_name isn't a '$class' it's a '$ref'";
a9153838 543 }
544 } else {
545 die <<WHOA;
546WHOA! I tried to call ->isa on your object and got some weird error.
547This should never happen. Please contact the author immediately.
548Here's the error.
549$@
550WHOA
551 }
552 }
553 elsif( !$rslt ) {
554 my $ref = ref $object;
6686786d 555 $diag = "$obj_name isn't a '$class' it's a '$ref'";
a9153838 556 }
d020a79a 557 }
a9153838 558
559
d020a79a 560
33459055 561 my $ok;
d020a79a 562 if( $diag ) {
b1ddf169 563 $ok = $tb->ok( 0, $name );
564 $tb->diag(" $diag\n");
d020a79a 565 }
566 else {
b1ddf169 567 $ok = $tb->ok( 1, $name );
d020a79a 568 }
33459055 569
570 return $ok;
d020a79a 571}
572
573
3f2ec160 574=item B<pass>
575
576=item B<fail>
577
578 pass($test_name);
579 fail($test_name);
580
581Sometimes you just want to say that the tests have passed. Usually
582the case is you've got some complicated condition that is difficult to
583wedge into an ok(). In this case, you can simply use pass() (to
584declare the test ok) or fail (for not ok). They are synonyms for
585ok(1) and ok(0).
586
587Use these very, very, very sparingly.
588
589=cut
590
d020a79a 591sub pass (;$) {
b1ddf169 592 my $tb = Test::More->builder;
593 $tb->ok(1, @_);
3f2ec160 594}
595
d020a79a 596sub fail (;$) {
b1ddf169 597 my $tb = Test::More->builder;
598 $tb->ok(0, @_);
3f2ec160 599}
600
601=back
602
a9153838 603
3f2ec160 604=head2 Module tests
605
606You usually want to test if the module you're testing loads ok, rather
607than just vomiting if its load fails. For such purposes we have
608C<use_ok> and C<require_ok>.
609
610=over 4
611
612=item B<use_ok>
613
3f2ec160 614 BEGIN { use_ok($module); }
d020a79a 615 BEGIN { use_ok($module, @imports); }
616
617These simply use the given $module and test to make sure the load
89c1e84a 618happened ok. It's recommended that you run use_ok() inside a BEGIN
d020a79a 619block so its functions are exported at compile-time and prototypes are
620properly honored.
621
622If @imports are given, they are passed through to the use. So this:
623
624 BEGIN { use_ok('Some::Module', qw(foo bar)) }
625
626is like doing this:
627
628 use Some::Module qw(foo bar);
3f2ec160 629
30e302f8 630Version numbers can be checked like so:
631
632 # Just like "use Some::Module 1.02"
633 BEGIN { use_ok('Some::Module', 1.02) }
634
635Don't try to do this:
a344be10 636
637 BEGIN {
638 use_ok('Some::Module');
639
640 ...some code that depends on the use...
641 ...happening at compile time...
642 }
643
30e302f8 644because the notion of "compile-time" is relative. Instead, you want:
a344be10 645
646 BEGIN { use_ok('Some::Module') }
647 BEGIN { ...some code that depends on the use... }
648
3f2ec160 649
650=cut
651
d020a79a 652sub use_ok ($;@) {
653 my($module, @imports) = @_;
654 @imports = () unless @imports;
b1ddf169 655 my $tb = Test::More->builder;
3f2ec160 656
30e302f8 657 my($pack,$filename,$line) = caller;
3f2ec160 658
a9153838 659 local($@,$!); # eval sometimes interferes with $!
30e302f8 660
661 if( @imports == 1 and $imports[0] =~ /^\d+(?:\.\d+)?$/ ) {
662 # probably a version check. Perl needs to see the bare number
663 # for it to work with non-Exporter based modules.
664 eval <<USE;
3f2ec160 665package $pack;
30e302f8 666use $module $imports[0];
3f2ec160 667USE
30e302f8 668 }
669 else {
670 eval <<USE;
671package $pack;
672use $module \@imports;
673USE
674 }
3f2ec160 675
b1ddf169 676 my $ok = $tb->ok( !$@, "use $module;" );
3f2ec160 677
678 unless( $ok ) {
0cd946aa 679 chomp $@;
30e302f8 680 $@ =~ s{^BEGIN failed--compilation aborted at .*$}
681 {BEGIN failed--compilation aborted at $filename line $line.}m;
b1ddf169 682 $tb->diag(<<DIAGNOSTIC);
a9153838 683 Tried to use '$module'.
684 Error: $@
3f2ec160 685DIAGNOSTIC
686
687 }
688
689 return $ok;
690}
691
d020a79a 692=item B<require_ok>
693
694 require_ok($module);
7483b81c 695 require_ok($file);
d020a79a 696
7483b81c 697Like use_ok(), except it requires the $module or $file.
d020a79a 698
699=cut
3f2ec160 700
701sub require_ok ($) {
702 my($module) = shift;
b1ddf169 703 my $tb = Test::More->builder;
3f2ec160 704
705 my $pack = caller;
706
7483b81c 707 # Try to deterine if we've been given a module name or file.
708 # Module names must be barewords, files not.
709 $module = qq['$module'] unless _is_module_name($module);
710
a9153838 711 local($!, $@); # eval sometimes interferes with $!
3f2ec160 712 eval <<REQUIRE;
713package $pack;
714require $module;
715REQUIRE
716
b1ddf169 717 my $ok = $tb->ok( !$@, "require $module;" );
3f2ec160 718
719 unless( $ok ) {
0cd946aa 720 chomp $@;
b1ddf169 721 $tb->diag(<<DIAGNOSTIC);
a9153838 722 Tried to require '$module'.
723 Error: $@
3f2ec160 724DIAGNOSTIC
725
726 }
727
728 return $ok;
729}
730
7483b81c 731
732sub _is_module_name {
733 my $module = shift;
734
735 # Module names start with a letter.
736 # End with an alphanumeric.
737 # The rest is an alphanumeric or ::
738 $module =~ s/\b::\b//g;
5143c659 739 $module =~ /^[a-zA-Z]\w*$/;
7483b81c 740}
741
d020a79a 742=back
3f2ec160 743
b1ddf169 744
745=head2 Complex data structures
746
747Not everything is a simple eq check or regex. There are times you
748need to see if two data structures are equivalent. For these
749instances Test::More provides a handful of useful functions.
750
751B<NOTE> I'm not quite sure what will happen with filehandles.
752
753=over 4
754
755=item B<is_deeply>
756
757 is_deeply( $this, $that, $test_name );
758
759Similar to is(), except that if $this and $that are references, it
760does a deep comparison walking each data structure to see if they are
761equivalent. If the two structures are different, it will display the
762place where they start differing.
763
764is_deeply() compares the dereferenced values of references, the
765references themselves (except for their type) are ignored. This means
766aspects such as blessing and ties are not considered "different".
767
768Test::Differences and Test::Deep provide more in-depth functionality
769along these lines.
770
771=cut
772
773use vars qw(@Data_Stack %Refs_Seen);
774my $DNE = bless [], 'Does::Not::Exist';
775sub is_deeply {
776 my $tb = Test::More->builder;
777
778 unless( @_ == 2 or @_ == 3 ) {
779 my $msg = <<WARNING;
780is_deeply() takes two or three args, you gave %d.
781This usually means you passed an array or hash instead
782of a reference to it
783WARNING
784 chop $msg; # clip off newline so carp() will put in line/file
785
786 _carp sprintf $msg, scalar @_;
787
788 return $tb->ok(0);
789 }
790
791 my($this, $that, $name) = @_;
792
793 $tb->_unoverload_str(\$that, \$this);
794
795 my $ok;
796 if( !ref $this and !ref $that ) { # neither is a reference
797 $ok = $tb->is_eq($this, $that, $name);
798 }
799 elsif( !ref $this xor !ref $that ) { # one's a reference, one isn't
800 $ok = $tb->ok(0, $name);
801 $tb->diag( _format_stack({ vals => [ $this, $that ] }) );
802 }
803 else { # both references
804 local @Data_Stack = ();
805 if( _deep_check($this, $that) ) {
806 $ok = $tb->ok(1, $name);
807 }
808 else {
809 $ok = $tb->ok(0, $name);
810 $tb->diag(_format_stack(@Data_Stack));
811 }
812 }
813
814 return $ok;
815}
816
817sub _format_stack {
818 my(@Stack) = @_;
819
820 my $var = '$FOO';
821 my $did_arrow = 0;
822 foreach my $entry (@Stack) {
823 my $type = $entry->{type} || '';
824 my $idx = $entry->{'idx'};
825 if( $type eq 'HASH' ) {
826 $var .= "->" unless $did_arrow++;
827 $var .= "{$idx}";
828 }
829 elsif( $type eq 'ARRAY' ) {
830 $var .= "->" unless $did_arrow++;
831 $var .= "[$idx]";
832 }
833 elsif( $type eq 'REF' ) {
834 $var = "\${$var}";
835 }
836 }
837
838 my @vals = @{$Stack[-1]{vals}}[0,1];
839 my @vars = ();
840 ($vars[0] = $var) =~ s/\$FOO/ \$got/;
841 ($vars[1] = $var) =~ s/\$FOO/\$expected/;
842
843 my $out = "Structures begin differing at:\n";
844 foreach my $idx (0..$#vals) {
845 my $val = $vals[$idx];
846 $vals[$idx] = !defined $val ? 'undef' :
847 $val eq $DNE ? "Does not exist" :
848 ref $val ? "$val" :
849 "'$val'";
850 }
851
852 $out .= "$vars[0] = $vals[0]\n";
853 $out .= "$vars[1] = $vals[1]\n";
854
855 $out =~ s/^/ /msg;
856 return $out;
857}
858
859
860sub _type {
861 my $thing = shift;
862
863 return '' if !ref $thing;
864
865 for my $type (qw(ARRAY HASH REF SCALAR GLOB Regexp)) {
866 return $type if UNIVERSAL::isa($thing, $type);
867 }
868
869 return '';
870}
871
872=back
873
874
875=head2 Diagnostics
876
877If you pick the right test function, you'll usually get a good idea of
878what went wrong when it failed. But sometimes it doesn't work out
879that way. So here we have ways for you to write your own diagnostic
880messages which are safer than just C<print STDERR>.
881
882=over 4
883
884=item B<diag>
885
886 diag(@diagnostic_message);
887
888Prints a diagnostic message which is guaranteed not to interfere with
889test output. Like C<print> @diagnostic_message is simply concatenated
890together.
891
892Handy for this sort of thing:
893
894 ok( grep(/foo/, @users), "There's a foo user" ) or
895 diag("Since there's no foo, check that /etc/bar is set up right");
896
897which would produce:
898
899 not ok 42 - There's a foo user
900 # Failed test 'There's a foo user'
901 # in foo.t at line 52.
902 # Since there's no foo, check that /etc/bar is set up right.
903
904You might remember C<ok() or diag()> with the mnemonic C<open() or
905die()>.
906
907B<NOTE> The exact formatting of the diagnostic output is still
908changing, but it is guaranteed that whatever you throw at it it won't
909interfere with the test.
910
911=cut
912
913sub diag {
914 my $tb = Test::More->builder;
915
916 $tb->diag(@_);
917}
918
919
920=back
921
922
3f2ec160 923=head2 Conditional tests
924
925Sometimes running a test under certain conditions will cause the
926test script to die. A certain function or method isn't implemented
927(such as fork() on MacOS), some resource isn't available (like a
d020a79a 928net connection) or a module isn't available. In these cases it's
929necessary to skip tests, or declare that they are supposed to fail
3f2ec160 930but will work in the future (a todo test).
931
a9153838 932For more details on the mechanics of skip and todo tests see
933L<Test::Harness>.
d020a79a 934
935The way Test::More handles this is with a named block. Basically, a
936block of tests which can be skipped over or made todo. It's best if I
937just show you...
3f2ec160 938
939=over 4
940
d020a79a 941=item B<SKIP: BLOCK>
942
943 SKIP: {
944 skip $why, $how_many if $condition;
3f2ec160 945
d020a79a 946 ...normal testing code goes here...
947 }
3f2ec160 948
a344be10 949This declares a block of tests that might be skipped, $how_many tests
950there are, $why and under what $condition to skip them. An example is
951the easiest way to illustrate:
3f2ec160 952
d020a79a 953 SKIP: {
a344be10 954 eval { require HTML::Lint };
3f2ec160 955
a344be10 956 skip "HTML::Lint not installed", 2 if $@;
d020a79a 957
a344be10 958 my $lint = new HTML::Lint;
60ffb308 959 isa_ok( $lint, "HTML::Lint" );
3f2ec160 960
a344be10 961 $lint->parse( $html );
60ffb308 962 is( $lint->errors, 0, "No errors found in HTML" );
a344be10 963 }
d020a79a 964
a344be10 965If the user does not have HTML::Lint installed, the whole block of
966code I<won't be run at all>. Test::More will output special ok's
967which Test::Harness interprets as skipped, but passing, tests.
0257f296 968
a344be10 969It's important that $how_many accurately reflects the number of tests
970in the SKIP block so the # of tests run will match up with your plan.
0257f296 971If your plan is C<no_plan> $how_many is optional and will default to 1.
a9153838 972
a344be10 973It's perfectly safe to nest SKIP blocks. Each SKIP block must have
974the label C<SKIP>, or Test::More can't work its magic.
a9153838 975
976You don't skip tests which are failing because there's a bug in your
a344be10 977program, or for which you don't yet have code written. For that you
978use TODO. Read on.
3f2ec160 979
980=cut
981
d020a79a 982#'#
1af51bd3 983sub skip {
d020a79a 984 my($why, $how_many) = @_;
b1ddf169 985 my $tb = Test::More->builder;
33459055 986
987 unless( defined $how_many ) {
d020a79a 988 # $how_many can only be avoided when no_plan is in use.
33459055 989 _carp "skip() needs to know \$how_many tests are in the block"
b1ddf169 990 unless $tb->has_plan eq 'no_plan';
d020a79a 991 $how_many = 1;
992 }
993
994 for( 1..$how_many ) {
b1ddf169 995 $tb->skip($why);
d020a79a 996 }
997
998 local $^W = 0;
999 last SKIP;
3f2ec160 1000}
1001
3f2ec160 1002
d020a79a 1003=item B<TODO: BLOCK>
3f2ec160 1004
d020a79a 1005 TODO: {
a9153838 1006 local $TODO = $why if $condition;
3f2ec160 1007
d020a79a 1008 ...normal testing code goes here...
1009 }
3f2ec160 1010
d020a79a 1011Declares a block of tests you expect to fail and $why. Perhaps it's
1012because you haven't fixed a bug or haven't finished a new feature:
3f2ec160 1013
d020a79a 1014 TODO: {
1015 local $TODO = "URI::Geller not finished";
3f2ec160 1016
d020a79a 1017 my $card = "Eight of clubs";
1018 is( URI::Geller->your_card, $card, 'Is THIS your card?' );
3f2ec160 1019
d020a79a 1020 my $spoon;
1021 URI::Geller->bend_spoon;
1022 is( $spoon, 'bent', "Spoon bending, that's original" );
1023 }
1024
1025With a todo block, the tests inside are expected to fail. Test::More
1026will run the tests normally, but print out special flags indicating
1027they are "todo". Test::Harness will interpret failures as being ok.
1028Should anything succeed, it will report it as an unexpected success.
a344be10 1029You then know the thing you had todo is done and can remove the
1030TODO flag.
d020a79a 1031
1032The nice part about todo tests, as opposed to simply commenting out a
4bd4e70a 1033block of tests, is it's like having a programmatic todo list. You know
d020a79a 1034how much work is left to be done, you're aware of what bugs there are,
1035and you'll know immediately when they're fixed.
1036
1037Once a todo test starts succeeding, simply move it outside the block.
1038When the block is empty, delete it.
1039
30e302f8 1040B<NOTE>: TODO tests require a Test::Harness upgrade else it will
b1ddf169 1041treat it as a normal failure. See L<CAVEATS and NOTES>).
30e302f8 1042
d020a79a 1043
a9153838 1044=item B<todo_skip>
1045
1046 TODO: {
1047 todo_skip $why, $how_many if $condition;
1048
1049 ...normal testing code...
1050 }
1051
89c1e84a 1052With todo tests, it's best to have the tests actually run. That way
a9153838 1053you'll know when they start passing. Sometimes this isn't possible.
1054Often a failing test will cause the whole program to die or hang, even
1055inside an C<eval BLOCK> with and using C<alarm>. In these extreme
1056cases you have no choice but to skip over the broken tests entirely.
1057
1058The syntax and behavior is similar to a C<SKIP: BLOCK> except the
1059tests will be marked as failing but todo. Test::Harness will
1060interpret them as passing.
1061
1062=cut
1063
1064sub todo_skip {
1065 my($why, $how_many) = @_;
b1ddf169 1066 my $tb = Test::More->builder;
a9153838 1067
1068 unless( defined $how_many ) {
1069 # $how_many can only be avoided when no_plan is in use.
1070 _carp "todo_skip() needs to know \$how_many tests are in the block"
b1ddf169 1071 unless $tb->has_plan eq 'no_plan';
a9153838 1072 $how_many = 1;
1073 }
1074
1075 for( 1..$how_many ) {
b1ddf169 1076 $tb->todo_skip($why);
a9153838 1077 }
1078
1079 local $^W = 0;
1080 last TODO;
1081}
1082
a344be10 1083=item When do I use SKIP vs. TODO?
1084
1085B<If it's something the user might not be able to do>, use SKIP.
1086This includes optional modules that aren't installed, running under
1087an OS that doesn't have some feature (like fork() or symlinks), or maybe
1088you need an Internet connection and one isn't available.
1089
1090B<If it's something the programmer hasn't done yet>, use TODO. This
1091is for any code you haven't written yet, or bugs you have yet to fix,
1092but want to put tests in your testing script (always a good idea).
1093
a9153838 1094
d020a79a 1095=back
3f2ec160 1096
3f2ec160 1097
b1ddf169 1098=head2 Test control
3f2ec160 1099
1100=over 4
1101
b1ddf169 1102=item B<BAIL_OUT>
33459055 1103
b1ddf169 1104 BAIL_OUT($reason);
33459055 1105
b1ddf169 1106Incidates to the harness that things are going so badly all testing
1107should terminate. This includes the running any additional test scripts.
33459055 1108
b1ddf169 1109This is typically used when testing cannot continue such as a critical
1110module failing to compile or a necessary external utility not being
1111available such as a database connection failing.
33459055 1112
b1ddf169 1113The test will exit with 255.
33459055 1114
b1ddf169 1115=cut
33459055 1116
b1ddf169 1117sub BAIL_OUT {
1118 my $reason = shift;
1119 my $tb = Test::More->builder;
33459055 1120
b1ddf169 1121 $tb->BAIL_OUT($reason);
33459055 1122}
1123
b1ddf169 1124=back
0257f296 1125
1126
5143c659 1127=head2 Discouraged comparison functions
1128
1129The use of the following functions is discouraged as they are not
1130actually testing functions and produce no diagnostics to help figure
1131out what went wrong. They were written before is_deeply() existed
1132because I couldn't figure out how to display a useful diff of two
1133arbitrary data structures.
1134
1135These functions are usually used inside an ok().
1136
1137 ok( eq_array(\@this, \@that) );
1138
1139C<is_deeply()> can do that better and with diagnostics.
1140
1141 is_deeply( \@this, \@that );
1142
1143They may be deprecated in future versions.
1144
b1ddf169 1145=over 4
5143c659 1146
3f2ec160 1147=item B<eq_array>
1148
5143c659 1149 my $is_eq = eq_array(\@this, \@that);
3f2ec160 1150
1151Checks if two arrays are equivalent. This is a deep check, so
1152multi-level structures are handled correctly.
1153
1154=cut
1155
1156#'#
7483b81c 1157sub eq_array {
1158 local @Data_Stack;
5143c659 1159 _deep_check(@_);
7483b81c 1160}
1161
1162sub _eq_array {
3f2ec160 1163 my($a1, $a2) = @_;
7483b81c 1164
0257f296 1165 if( grep !_type($_) eq 'ARRAY', $a1, $a2 ) {
7483b81c 1166 warn "eq_array passed a non-array ref";
1167 return 0;
1168 }
1169
3f2ec160 1170 return 1 if $a1 eq $a2;
1171
1172 my $ok = 1;
33459055 1173 my $max = $#$a1 > $#$a2 ? $#$a1 : $#$a2;
1174 for (0..$max) {
1175 my $e1 = $_ > $#$a1 ? $DNE : $a1->[$_];
1176 my $e2 = $_ > $#$a2 ? $DNE : $a2->[$_];
1177
1178 push @Data_Stack, { type => 'ARRAY', idx => $_, vals => [$e1, $e2] };
3f2ec160 1179 $ok = _deep_check($e1,$e2);
33459055 1180 pop @Data_Stack if $ok;
1181
3f2ec160 1182 last unless $ok;
1183 }
7483b81c 1184
3f2ec160 1185 return $ok;
1186}
1187
1188sub _deep_check {
1189 my($e1, $e2) = @_;
b1ddf169 1190 my $tb = Test::More->builder;
1191
3f2ec160 1192 my $ok = 0;
1193
5143c659 1194 # Effectively turn %Refs_Seen into a stack. This avoids picking up
1195 # the same referenced used twice (such as [\$a, \$a]) to be considered
1196 # circular.
1197 local %Refs_Seen = %Refs_Seen;
1198
d020a79a 1199 {
4bd4e70a 1200 # Quiet uninitialized value warnings when comparing undefs.
d020a79a 1201 local $^W = 0;
1202
b1ddf169 1203 $tb->_unoverload_str(\$e1, \$e2);
7483b81c 1204
1205 # Either they're both references or both not.
1206 my $same_ref = !(!ref $e1 xor !ref $e2);
5143c659 1207 my $not_ref = (!ref $e1 and !ref $e2);
7483b81c 1208
1209 if( defined $e1 xor defined $e2 ) {
1210 $ok = 0;
1211 }
1212 elsif ( $e1 == $DNE xor $e2 == $DNE ) {
1213 $ok = 0;
1214 }
1215 elsif ( $same_ref and ($e1 eq $e2) ) {
d020a79a 1216 $ok = 1;
3f2ec160 1217 }
5143c659 1218 elsif ( $not_ref ) {
1219 push @Data_Stack, { type => '', vals => [$e1, $e2] };
1220 $ok = 0;
1221 }
3f2ec160 1222 else {
5143c659 1223 if( $Refs_Seen{$e1} ) {
1224 return $Refs_Seen{$e1} eq $e2;
1225 }
1226 else {
1227 $Refs_Seen{$e1} = "$e2";
1228 }
1229
0257f296 1230 my $type = _type($e1);
5143c659 1231 $type = 'DIFFERENT' unless _type($e2) eq $type;
0257f296 1232
5143c659 1233 if( $type eq 'DIFFERENT' ) {
1234 push @Data_Stack, { type => $type, vals => [$e1, $e2] };
0257f296 1235 $ok = 0;
1236 }
1237 elsif( $type eq 'ARRAY' ) {
7483b81c 1238 $ok = _eq_array($e1, $e2);
d020a79a 1239 }
0257f296 1240 elsif( $type eq 'HASH' ) {
7483b81c 1241 $ok = _eq_hash($e1, $e2);
d020a79a 1242 }
0257f296 1243 elsif( $type eq 'REF' ) {
5143c659 1244 push @Data_Stack, { type => $type, vals => [$e1, $e2] };
33459055 1245 $ok = _deep_check($$e1, $$e2);
1246 pop @Data_Stack if $ok;
1247 }
0257f296 1248 elsif( $type eq 'SCALAR' ) {
33459055 1249 push @Data_Stack, { type => 'REF', vals => [$e1, $e2] };
1250 $ok = _deep_check($$e1, $$e2);
7483b81c 1251 pop @Data_Stack if $ok;
33459055 1252 }
5143c659 1253 else {
1254 _whoa(1, "No type in _deep_check");
1255 }
3f2ec160 1256 }
1257 }
d020a79a 1258
3f2ec160 1259 return $ok;
1260}
1261
1262
5143c659 1263sub _whoa {
1264 my($check, $desc) = @_;
1265 if( $check ) {
1266 die <<WHOA;
1267WHOA! $desc
1268This should never happen! Please contact the author immediately!
1269WHOA
1270 }
1271}
1272
1273
3f2ec160 1274=item B<eq_hash>
1275
5143c659 1276 my $is_eq = eq_hash(\%this, \%that);
3f2ec160 1277
1278Determines if the two hashes contain the same keys and values. This
1279is a deep check.
1280
1281=cut
1282
1283sub eq_hash {
7483b81c 1284 local @Data_Stack;
5143c659 1285 return _deep_check(@_);
7483b81c 1286}
1287
1288sub _eq_hash {
3f2ec160 1289 my($a1, $a2) = @_;
7483b81c 1290
0257f296 1291 if( grep !_type($_) eq 'HASH', $a1, $a2 ) {
7483b81c 1292 warn "eq_hash passed a non-hash ref";
1293 return 0;
1294 }
1295
3f2ec160 1296 return 1 if $a1 eq $a2;
1297
1298 my $ok = 1;
33459055 1299 my $bigger = keys %$a1 > keys %$a2 ? $a1 : $a2;
1300 foreach my $k (keys %$bigger) {
1301 my $e1 = exists $a1->{$k} ? $a1->{$k} : $DNE;
1302 my $e2 = exists $a2->{$k} ? $a2->{$k} : $DNE;
1303
1304 push @Data_Stack, { type => 'HASH', idx => $k, vals => [$e1, $e2] };
3f2ec160 1305 $ok = _deep_check($e1, $e2);
33459055 1306 pop @Data_Stack if $ok;
1307
3f2ec160 1308 last unless $ok;
1309 }
1310
1311 return $ok;
1312}
1313
1314=item B<eq_set>
1315
5143c659 1316 my $is_eq = eq_set(\@this, \@that);
3f2ec160 1317
1318Similar to eq_array(), except the order of the elements is B<not>
1319important. This is a deep check, but the irrelevancy of order only
1320applies to the top level.
1321
5143c659 1322 ok( eq_set(\@this, \@that) );
1323
1324Is better written:
1325
1326 is_deeply( [sort @this], [sort @that] );
1327
3c4b39be 1328B<NOTE> By historical accident, this is not a true set comparison.
60ffb308 1329While the order of elements does not matter, duplicate elements do.
1330
b1ddf169 1331B<NOTE> eq_set() does not know how to deal with references at the top
1332level. The following is an example of a comparison which might not work:
1333
1334 eq_set([\1, \2], [\2, \1]);
1335
5143c659 1336Test::Deep contains much better set comparison functions.
1337
3f2ec160 1338=cut
1339
3f2ec160 1340sub eq_set {
1341 my($a1, $a2) = @_;
1342 return 0 unless @$a1 == @$a2;
1343
1344 # There's faster ways to do this, but this is easiest.
7483b81c 1345 local $^W = 0;
1346
b1ddf169 1347 # It really doesn't matter how we sort them, as long as both arrays are
1348 # sorted with the same algorithm.
1349 #
1350 # Ensure that references are not accidentally treated the same as a
1351 # string containing the reference.
1352 #
7483b81c 1353 # Have to inline the sort routine due to a threading/sort bug.
1354 # See [rt.cpan.org 6782]
b1ddf169 1355 #
1356 # I don't know how references would be sorted so we just don't sort
1357 # them. This means eq_set doesn't really work with refs.
7483b81c 1358 return eq_array(
b1ddf169 1359 [grep(ref, @$a1), sort( grep(!ref, @$a1) )],
1360 [grep(ref, @$a2), sort( grep(!ref, @$a2) )],
7483b81c 1361 );
3f2ec160 1362}
1363
3f2ec160 1364=back
1365
d020a79a 1366
a9153838 1367=head2 Extending and Embedding Test::More
d020a79a 1368
a9153838 1369Sometimes the Test::More interface isn't quite enough. Fortunately,
1370Test::More is built on top of Test::Builder which provides a single,
1371unified backend for any test library to use. This means two test
1372libraries which both use Test::Builder B<can be used together in the
1373same program>.
1374
1375If you simply want to do a little tweaking of how the tests behave,
1376you can access the underlying Test::Builder object like so:
3f2ec160 1377
d020a79a 1378=over 4
1379
a9153838 1380=item B<builder>
d020a79a 1381
a9153838 1382 my $test_builder = Test::More->builder;
d020a79a 1383
a9153838 1384Returns the Test::Builder object underlying Test::More for you to play
1385with.
1386
d020a79a 1387
a9153838 1388=back
3f2ec160 1389
d020a79a 1390
30e302f8 1391=head1 EXIT CODES
1392
1393If all your tests passed, Test::Builder will exit with zero (which is
1394normal). If anything failed it will exit with how many failed. If
1395you run less (or more) tests than you planned, the missing (or extras)
1396will be considered failures. If no tests were ever run Test::Builder
1397will throw a warning and exit with 255. If the test died, even after
1398having successfully completed all its tests, it will still be
1399considered a failure and will exit with 255.
1400
1401So the exit codes are...
1402
1403 0 all tests successful
b1ddf169 1404 255 test died or all passed but wrong # of tests run
30e302f8 1405 any other number how many failed (including missing or extras)
1406
1407If you fail more than 254 tests, it will be reported as 254.
1408
5143c659 1409B<NOTE> This behavior may go away in future versions.
1410
30e302f8 1411
7483b81c 1412=head1 CAVEATS and NOTES
a9153838 1413
7483b81c 1414=over 4
d020a79a 1415
7483b81c 1416=item Backwards compatibility
1417
1418Test::More works with Perls as old as 5.004_05.
1419
1420
1421=item Overloaded objects
1422
b1ddf169 1423String overloaded objects are compared B<as strings> (or in cmp_ok()'s
1424case, strings or numbers as appropriate to the comparison op). This
1425prevents Test::More from piercing an object's interface allowing
1426better blackbox testing. So if a function starts returning overloaded
1427objects instead of bare strings your tests won't notice the
1428difference. This is good.
7483b81c 1429
1430However, it does mean that functions like is_deeply() cannot be used to
1431test the internals of string overloaded objects. In this case I would
1432suggest Test::Deep which contains more flexible testing functions for
1433complex data structures.
a9153838 1434
a9153838 1435
30e302f8 1436=item Threads
1437
1438Test::More will only be aware of threads if "use threads" has been done
1439I<before> Test::More is loaded. This is ok:
1440
1441 use threads;
1442 use Test::More;
1443
1444This may cause problems:
1445
1446 use Test::More
1447 use threads;
1448
d020a79a 1449
30e302f8 1450=item Test::Harness upgrade
3f2ec160 1451
d020a79a 1452no_plan and todo depend on new Test::Harness features and fixes. If
a9153838 1453you're going to distribute tests that use no_plan or todo your
1454end-users will have to upgrade Test::Harness to the latest one on
1455CPAN. If you avoid no_plan and TODO tests, the stock Test::Harness
1456will work fine.
d020a79a 1457
30e302f8 1458Installing Test::More should also upgrade Test::Harness.
d020a79a 1459
1460=back
3f2ec160 1461
3f2ec160 1462
1463=head1 HISTORY
1464
1465This is a case of convergent evolution with Joshua Pritikin's Test
4bd4e70a 1466module. I was largely unaware of its existence when I'd first
3f2ec160 1467written my own ok() routines. This module exists because I can't
1468figure out how to easily wedge test names into Test's interface (along
1469with a few other problems).
1470
1471The goal here is to have a testing utility that's simple to learn,
1472quick to use and difficult to trip yourself up with while still
1473providing more flexibility than the existing Test.pm. As such, the
1474names of the most common routines are kept tiny, special cases and
1475magic side-effects are kept to a minimum. WYSIWYG.
1476
1477
1478=head1 SEE ALSO
1479
1480L<Test::Simple> if all this confuses you and you just want to write
89c1e84a 1481some tests. You can upgrade to Test::More later (it's forward
3f2ec160 1482compatible).
1483
a9153838 1484L<Test> is the old testing module. Its main benefit is that it has
1485been distributed with Perl since 5.004_05.
3f2ec160 1486
1487L<Test::Harness> for details on how your test results are interpreted
1488by Perl.
1489
30e302f8 1490L<Test::Differences> for more ways to test complex data structures.
1491And it plays well with Test::More.
1492
1493L<Test::Class> is like XUnit but more perlish.
1494
1495L<Test::Deep> gives you more powerful complex data structure testing.
1496
1497L<Test::Unit> is XUnit style testing.
3f2ec160 1498
4bd4e70a 1499L<Test::Inline> shows the idea of embedded testing.
3f2ec160 1500
30e302f8 1501L<Bundle::Test> installs a whole bunch of useful test modules.
3f2ec160 1502
4bd4e70a 1503
1504=head1 AUTHORS
1505
a9153838 1506Michael G Schwern E<lt>schwern@pobox.comE<gt> with much inspiration
1507from Joshua Pritikin's Test module and lots of help from Barrie
7483b81c 1508Slaymaker, Tony Bowden, blackstar.co.uk, chromatic, Fergal Daly and
1509the perl-qa gang.
1510
1511
1512=head1 BUGS
1513
1514See F<http://rt.cpan.org> to report and view bugs.
4bd4e70a 1515
1516
1517=head1 COPYRIGHT
1518
7483b81c 1519Copyright 2001, 2002, 2004 by Michael G Schwern E<lt>schwern@pobox.comE<gt>.
4bd4e70a 1520
1521This program is free software; you can redistribute it and/or
1522modify it under the same terms as Perl itself.
1523
a9153838 1524See F<http://www.perl.com/perl/misc/Artistic.html>
4bd4e70a 1525
3f2ec160 1526=cut
1527
15281;