X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FTest.pm;h=d497217ff11f7d00d4cf851e513f660e9a0db236;hb=411cc70a34f8fb9bcdf0a5306f32b31a7092ea1e;hp=77728bc323730d6bae272b61272da692796494cf;hpb=76fbd8c4ea7bb4d7a18a2c0a1d508a67659f3068;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/Test.pm b/lib/Test.pm index 77728bc..d497217 100644 --- a/lib/Test.pm +++ b/lib/Test.pm @@ -6,20 +6,30 @@ use strict; use Carp; use vars (qw($VERSION @ISA @EXPORT @EXPORT_OK $ntest $TestLevel), #public-ish - qw($TESTOUT $ONFAIL %todo %history $planned @FAILDETAIL)#private-ish + qw($TESTOUT $TESTERR + $ONFAIL %todo %history $planned @FAILDETAIL) #private-ish ); -$VERSION = '1.17_00'; +# In case a test is run in a persistent environment. +sub _reset_globals { + %todo = (); + %history = (); + @FAILDETAIL = (); + $ntest = 1; + $TestLevel = 0; # how many extra stack frames to skip + $planned = 0; +} + +$VERSION = '1.20'; require Exporter; @ISA=('Exporter'); @EXPORT = qw(&plan &ok &skip); -@EXPORT_OK = qw($ntest $TESTOUT); +@EXPORT_OK = qw($ntest $TESTOUT $TESTERR); -$TestLevel = 0; # how many extra stack frames to skip $|=1; -$ntest=1; $TESTOUT = *STDOUT{IO}; +$TESTERR = *STDERR{IO}; # Use of this variable is strongly discouraged. It is set mainly to # help test coverage analyzers know which test is running. @@ -64,6 +74,9 @@ Test - provides a simple framework for writing test scripts =head1 DESCRIPTION +B If you are writing a new test, we I you use +the new Test::Simple and Test::More modules instead. + L expects to see particular output when it executes tests. This module aims to make writing proper test scripts just a little bit easier (and less error prone :-). @@ -109,6 +122,8 @@ sub plan { local($\, $,); # guard against -l and other things that screw with # print + _reset_globals(); + my $max=0; for (my $x=0; $x < @_; $x+=2) { my ($k,$v) = @_[$x,$x+1]; @@ -272,13 +287,13 @@ sub ok ($;$$) { $context .= ' *TODO*' if $todo; if (!defined $expected) { if (!$diag) { - print $TESTOUT "# Failed test $ntest in $context\n"; + print $TESTERR "# Failed test $ntest in $context\n"; } else { - print $TESTOUT "# Failed test $ntest in $context: $diag\n"; + print $TESTERR "# Failed test $ntest in $context: $diag\n"; } } else { my $prefix = "Test $ntest"; - print $TESTOUT "# $prefix got: ". + print $TESTERR "# $prefix got: ". (defined $result? "'$result'":'')." ($context)\n"; $prefix = ' ' x (length($prefix) - 5); if (defined $regex) { @@ -288,9 +303,9 @@ sub ok ($;$$) { $expected = "'$expected'"; } if (!$diag) { - print $TESTOUT "# $prefix Expected: $expected\n"; + print $TESTERR "# $prefix Expected: $expected\n"; } else { - print $TESTOUT "# $prefix Expected: $expected ($diag)\n"; + print $TESTERR "# $prefix Expected: $expected ($diag)\n"; } } push @FAILDETAIL, $detail; @@ -421,32 +436,33 @@ Again, best bet is to use the single argument form: ok( $fileglob eq '/path/to/some/*stuff/' ); -=head1 TODO +=head1 NOTE -Add todo(). - -Allow named tests. - -Implement noplan(). +This module is no longer actively being developed, only bug fixes and +small tweaks (I'll still accept patches). If you desire additional +functionality, consider L or L. =head1 SEE ALSO L, L, L, L -L is an interesting alternative testing library. +L for building your own testing library. + +L is an interesting XUnit-style testing library. + +L and L let you embed tests in code. =head1 AUTHOR Copyright (c) 1998-2000 Joshua Nathaniel Pritikin. All rights reserved. -Copyright (c) 2001 Michael G Schwern. +Copyright (c) 2001-2002 Michael G Schwern. Current maintainer, Michael G Schwern This package is free software and is provided "as is" without express or implied warranty. It may be used, redistributed and/or modified -under the terms of the Perl Artistic License (see -http://www.perl.com/perl/misc/Artistic.html) +under the same terms as Perl itself. =cut