Hi guys! There is one more problem with using Error with Test::Unit. If
I throw an exception (Error::Simple) it is now caught by Test::Unit and
stored. When time comes to print out a report about it HarnessUnit and
TestFailure just call to_string() method on the stored exception object.
Which in case of Error.pm (and potentially who knows what else) does not
have that method.

And as a result it prints absolutely meaningless error messages if a
test fails.

Here is what I did and what works for me:

Index: lib/Test/Unit/HarnessUnit.pm
===================================================================
RCS file: /cvsroot/perlunit/src/Test-Unit/lib/Test/Unit/HarnessUnit.pm,v
retrieving revision 1.8
diff -u -r1.8 HarnessUnit.pm
--- lib/Test/Unit/HarnessUnit.pm        2001/02/22 18:45:59     1.8
+++ lib/Test/Unit/HarnessUnit.pm        2001/05/21 21:20:46
@@ -38,10 +38,12 @@
 sub not_ok {
     my $self = shift;
     my ($test, $exception) = @_;
-    $self->_print("\nnot ok ERROR "
+    my $se=ref($exception) && $exception->isa('Test::Unit::Exception')
+            ? $exception->to_string() : "$exception";
+    $self->_print("not ok ERROR "
                  . $test->name()
                  . "\n"
-                 . $exception->to_string()
+                 . $se
                  . "\n");
 }
 
@@ -118,7 +120,7 @@
     my $suite=Test::Unit::TestLoader::load(@args);
     if ($suite) {
        my $count=$suite->count_test_cases();
-       $self->_print("\nSTARTING TEST RUN\n1..$count\n");
+       $self->_print("STARTING TEST RUN\n1..$count\n");
        $self->do_run($suite);
        exit(0);
     } else {
Index: lib/Test/Unit/TestFailure.pm
===================================================================
RCS file: /cvsroot/perlunit/src/Test-Unit/lib/Test/Unit/TestFailure.pm,v
retrieving revision 1.5
diff -u -r1.5 TestFailure.pm
--- lib/Test/Unit/TestFailure.pm        2001/03/08 09:35:22     1.5
+++ lib/Test/Unit/TestFailure.pm        2001/05/21 21:20:46
@@ -23,8 +23,10 @@
 
 sub to_string {
     my $self = shift;
+    my $e=$self->thrown_exception();
     return $self->failed_test()->to_string() . "\n" .
-       $self->thrown_exception()->to_string();
+              ref($e) && $e->isa('Test::Unit::Exception') ? $e->to_string()
+                                                          : "$e";
 }
 
 1;




_______________________________________________
Perlunit-devel mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/perlunit-devel

Reply via email to