require Exporter;
use vars qw($VERSION @ISA @EXPORT $TODO);
-$VERSION = '0.18';
+$VERSION = '0.19';
@ISA = qw(Exporter);
@EXPORT = qw(ok use_ok require_ok
is isnt like
my $ok = ok( !$@, "use $module;" );
unless( $ok ) {
+ chomp $@;
my_print *TESTERR, <<DIAGNOSTIC;
# Tried to use '$module'.
# Error: $@
my $ok = ok( !$@, "require $module;" );
unless( $ok ) {
+ chomp $@;
my_print *TESTERR, <<DIAGNOSTIC;
# Tried to require '$module'.
# Error: $@
use vars qw($VERSION);
-$VERSION = '0.18';
+$VERSION = '0.19';
my(@Test_Results) = ();
my($Num_Tests, $Planned_Tests, $Test_Died) = (0,0,0);
$| = 1;
open(*TESTOUT, ">&STDOUT") or _whoa(1, "Can't dup STDOUT!");
-open(*TESTERR, ">&STDERR") or _whoa(1, "Can't dup STDERR!");
+open(*TESTERR, ">&STDOUT") or _whoa(1, "Can't dup STDOUT!");
{
my $orig_fh = select TESTOUT;
$| = 1;
$Num_Tests++;
- my_print *TESTERR, <<ERR if defined $name and $name !~ /\D/;
+ my_print *TESTERR, <<ERR if defined $name and $name =~ /^[\d\s]+$/;
You named your test '$name'. You shouldn't use numbers for your test names.
Very confusing.
ERR
my($pack, $file, $line) = caller;
- if( $pack eq 'Test::More' ) { # special case for Test::More's calls
+ # temporary special case for Test::More & Parrot::Test's calls.
+ if( $pack eq 'Test::More' || $pack eq 'Parrot::Test' ) {
($pack, $file, $line) = caller(1);
}
}
$msg .= "ok $Num_Tests";
- if( @_ == 2 ) {
+ if( defined $name ) {
$name =~ s|#|\\#|g; # # in a name can confuse Test::Harness.
$msg .= " - $name";
}
my_print *TESTOUT, $msg;
#'#
- unless( $test or $is_todo ) {
- my_print *TESTERR, "# Failed test ($file at line $line)\n";
+ unless( $test ) {
+ my $msg = $is_todo ? "Failed (TODO)" : "Failed";
+ my_print *TESTERR, "# $msg test ($file at line $line)\n";
}
return $test ? 1 : 0;
Revision history for Perl extension Test::Simple
+0.19 Tue Sep 18 17:48:32 EDT 2001
+ * Test::Simple and Test::More no longer print their diagnostics
+ to STDERR. It instead goes to STDOUT.
+ * TODO tests which fail now print full failure diagnostics.
+ - Minor bug in ok()'s test name diagnostics made it think a blank
+ name was a number.
+ - ok() less draconian about test names
+ - Added temporary special case for Parrot::Test
+ - Now requiring File::Spec for our tests.
+
0.18 Wed Sep 5 20:35:24 EDT 2001
* ***API CHANGE*** can_ok() only counts as one test
- can_ok() has better diagnostics
BEGIN {
chdir 't' if -d 't';
@INC = '../lib';
- use File::Spec;
}
# Can't use Test.pm, that's a 5.005 thing.
package My::Test;
+use File::Spec;
+
my $test_num = 1;
# Utility testing functions.
sub ok ($;$) {
print "1..".keys(%Tests)."\n";
-my $lib = File::Spec->catdir('lib', 'Test', 'Simple', 'sample_tests');
-
+my $lib = File::Spec->catdir(qw(lib Test Simple sample_tests));
while( my($test_name, $exit_codes) = each %Tests ) {
my($exit_code) = $exit_codes->[$IsVMS ? 1 : 0];
my $file = File::Spec->catfile($lib, $test_name);
-
my $wait_stat = system(qq{$^X -"I../lib" -"I../t/lib" $file});
my $actual_exit = $wait_stat >> 8;
Test::Simple->import(tests => 3);
+#line 30
ok(1, 'Foo');
ok(0, 'Bar');
ok(1, 'Yar');
# Failed test \\($filename at line 43\\)
# Tried to use 'Hooble::mooble::yooble'.
# Error: Can't locate Hooble.* in \\\@INC .*
-
# Failed test \\($filename at line 44\\)
# Tried to require 'ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble'.
# Error: Can't locate ALL.* in \\\@INC .*
-
# Looks like you failed 10 tests of 10.
ERR
Test::Simple->import(tests => 5);
+#line 32
ok( 1, 'passing' );
ok( 2, 'passing still' );
ok( 3, 'still passing' );
Test::Simple->import(tests => 5);
+#line 30
ok(1, 'Foo');
ok(0, 'Bar');
Test::More->import(skip_all => 'Need the new Test::Harness');
}
else {
- Test::More->import(tests => 5);
+ Test::More->import(tests => 13);
}
}
}
pass("This is still not todo");
+
+
+TODO: {
+ local $TODO = "testing that error messages don't leak out of todo";
+
+ ok( 'this' eq 'that', 'ok' );
+
+ like( 'this', '/that/', 'like' );
+ is( 'this', 'that', 'is' );
+ isnt( 'this', 'this', 'isnt' );
+
+ can_ok('Fooble', 'yarble');
+ isa_ok('Fooble', 'yarble');
+ use_ok('Fooble');
+ require_ok('Fooble');
+}
=head1 DESCRIPTION
- AHHHHHHH!!!! NOT B<TESTING>! Anything but testing!
- Beat me, whip me, send me to I<Detroit>, but don't make
- me write tests!
- *sob*
+B<AHHHHHHH!!!! NOT TESTING! Anything but testing!
+Beat me, whip me, send me to Detroit, but don't make
+me write tests!>
+
+B<*sob*>
+
+B<Besides, I don't know how to write the damned things.>
- Besides, I don't know how to write the damned things.
Is this you? Is writing tests right up there with writing
-documentation and having your fingernails pulled out?
+documentation and having your fingernails pulled out? Did you open up
+a test and read
+
+ ######## We start with some black magic
+
+and decide that's quite enough for you?
+
+It's ok. That's all gone now. We've done all the black magic for
+you. And here are the tricks...
=head2 Nuts and bolts of testing.