Heya, the attached patch is a cvs diff which hides all this Java-like
'to_string' behind Perl's stringification. I notice Piers had already
done this with his module ;-)
I don't think this breaks anything, but I really think we need some
more tests (and documentation, eh?)... <g>
More patches to come as I understand more ;-)
Leon
--
Leon Brocard.............................http://www.astray.com/
yapc::Europe............................http://yapc.org/Europe/
... Useless invention no. 404: Caffeine-free Diet Coke
? stringify.diff
Index: Unit/Exception.pm
===================================================================
RCS file: /cvsroot/perlunit/src/Test-Unit/lib/Test/Unit/Exception.pm,v
retrieving revision 1.11
diff -d -u -r1.11 Exception.pm
--- Unit/Exception.pm 2001/03/08 09:35:22 1.11
+++ Unit/Exception.pm 2001/03/11 21:24:56
@@ -1,6 +1,7 @@
package Test::Unit::Exception;
use strict;
use constant DEBUG => 0;
+use overload '""' => \&to_string;
sub new {
my $pkg = shift;
Index: Unit/HarnessUnit.pm
===================================================================
RCS file: /cvsroot/perlunit/src/Test-Unit/lib/Test/Unit/HarnessUnit.pm,v
retrieving revision 1.8
diff -d -u -r1.8 HarnessUnit.pm
--- Unit/HarnessUnit.pm 2001/02/22 18:45:59 1.8
+++ Unit/HarnessUnit.pm 2001/03/11 21:24:56
@@ -41,7 +41,7 @@
$self->_print("\nnot ok ERROR "
. $test->name()
. "\n"
- . $exception->to_string()
+ . $exception
. "\n");
}
Index: Unit/Test.pm
===================================================================
RCS file: /cvsroot/perlunit/src/Test-Unit/lib/Test/Unit/Test.pm,v
retrieving revision 1.6
diff -d -u -r1.6 Test.pm
--- Unit/Test.pm 2001/02/20 21:31:05 1.6
+++ Unit/Test.pm 2001/03/11 21:24:56
@@ -3,7 +3,7 @@
use constant DEBUG => 0;
use base qw(Test::Unit::Assert);
-
+use overload '""' => \&to_string;
use Carp;
sub count_test_cases {
Index: Unit/TestCase.pm
===================================================================
RCS file: /cvsroot/perlunit/src/Test-Unit/lib/Test/Unit/TestCase.pm,v
retrieving revision 1.19
diff -d -u -r1.19 TestCase.pm
--- Unit/TestCase.pm 2001/03/07 20:15:14 1.19
+++ Unit/TestCase.pm 2001/03/11 21:24:57
@@ -7,6 +7,7 @@
use Test::Unit::ExceptionFailure;
use Test::Unit::ExceptionError;
use Test::Unit::TestResult;
+use overload '""' => \&to_string;
use vars '@ISA';
Index: Unit/TestFailure.pm
===================================================================
RCS file: /cvsroot/perlunit/src/Test-Unit/lib/Test/Unit/TestFailure.pm,v
retrieving revision 1.5
diff -d -u -r1.5 TestFailure.pm
--- Unit/TestFailure.pm 2001/03/08 09:35:22 1.5
+++ Unit/TestFailure.pm 2001/03/11 21:25:18
@@ -1,6 +1,7 @@
package Test::Unit::TestFailure;
use strict;
use constant DEBUG => 0;
+use overload '""' => \&to_string;
sub new {
my $class = shift;
@@ -23,8 +24,8 @@
sub to_string {
my $self = shift;
- return $self->failed_test()->to_string() . "\n" .
- $self->thrown_exception()->to_string();
+ return $self->failed_test() . "\n" .
+ $self->thrown_exception();
}
1;
Index: Unit/TestResult.pm
===================================================================
RCS file: /cvsroot/perlunit/src/Test-Unit/lib/Test/Unit/TestResult.pm,v
retrieving revision 1.8
diff -d -u -r1.8 TestResult.pm
--- Unit/TestResult.pm 2001/03/05 16:29:10 1.8
+++ Unit/TestResult.pm 2001/03/11 21:25:18
@@ -1,6 +1,7 @@
package Test::Unit::TestResult;
use strict;
use constant DEBUG => 0;
+use overload '""' => \&to_string;
use Test::Unit::TestFailure;
Index: Unit/TestRunner.pm
===================================================================
RCS file: /cvsroot/perlunit/src/Test-Unit/lib/Test/Unit/TestRunner.pm,v
retrieving revision 1.9
diff -d -u -r1.9 TestRunner.pm
--- Unit/TestRunner.pm 2001/03/08 09:35:22 1.9
+++ Unit/TestRunner.pm 2001/03/11 21:25:18
@@ -103,7 +103,7 @@
my $i = 0;
for my $e (@{$result->errors()}) {
$i++;
- $self->_print($i, ") ", $e->to_string());
+ $self->_print($i, ") ", $e);
}
}
}
@@ -120,7 +120,7 @@
my $i = 0;
for my $e (@{$result->failures()}) {
$i++;
- $self->_print($i, ") ", $e->to_string());
+ $self->_print($i, ") ", $e);
}
}
}
Index: Unit/TestSuite.pm
===================================================================
RCS file: /cvsroot/perlunit/src/Test-Unit/lib/Test/Unit/TestSuite.pm,v
retrieving revision 1.11
diff -d -u -r1.11 TestSuite.pm
--- Unit/TestSuite.pm 2001/02/27 10:51:36 1.11
+++ Unit/TestSuite.pm 2001/03/11 21:25:19
@@ -2,6 +2,7 @@
use strict;
use constant DEBUG => 0;
use base qw(Test::Unit::Test);
+use overload '""' => \&to_string;
use Test::Unit::TestCase;
use Test::Unit::InnerClass;
Index: Unit/TkTestRunner.pm
===================================================================
RCS file: /cvsroot/perlunit/src/Test-Unit/lib/Test/Unit/TkTestRunner.pm,v
retrieving revision 1.11
diff -d -u -r1.11 TkTestRunner.pm
--- Unit/TkTestRunner.pm 2001/02/20 21:31:05 1.11
+++ Unit/TkTestRunner.pm 2001/03/11 21:25:22
@@ -350,8 +350,7 @@
my $dialog=$self->{'frame'}->DialogBox(-title=>'Details',-buttons=>['OK']);
my $text=$dialog->add("Scrolled","ROText", -width=>80, -height=>20)->pack;
$text->insert("end",$self->{'exceptions'}
- ->[$self->{'failure_list'}->curselection]
- ->to_string());
+ ->[$self->{'failure_list'}->curselection]);
$dialog->Show();
}
Index: Unit/UnitHarness.pm
===================================================================
RCS file: /cvsroot/perlunit/src/Test-Unit/lib/Test/Unit/UnitHarness.pm,v
retrieving revision 1.7
diff -d -u -r1.7 UnitHarness.pm
--- Unit/UnitHarness.pm 2001/02/20 21:31:05 1.7
+++ Unit/UnitHarness.pm 2001/03/11 21:25:23
@@ -12,6 +12,7 @@
use Test::Unit::TestCase;
use Test::Unit::InnerClass;
use Test::Unit::Exception;
+use overload '""' => \&to_string;
use strict;