Subject: | Bug in Test::More::_deep_check() |
Date: | Mon, 31 Jul 2006 14:46:33 +1000 |
To: | <bug-Test-Simple [...] rt.cpan.org> |
From: | "Sisyphus" <sisyphus1 [...] optusnet.com.au> |
Hi,
The bug demo files 'Foo.pm' and 'footest.pl' are as follows:
-------------------
D:\pscrpt\test-more>cat Foo.pm
package Foo;
use overload
'eq' => \&overload_equiv,
'==' => \&overload_equiv;
sub new {
my $class = shift;
my $self = {};
bless $self, $class;
return $self;
}
sub overload_equiv {
if (ref($_[0]) ne 'Foo' || ref($_[1]) ne 'Foo') {
print ref($_[0]), " ", ref($_[1]), "\n";
die "Invalid object passed to overload_equiv\n";
}
print "equivalence overloaded\n";
return 1; # change to 0 ... makes little difference
}
1;
D:\pscrpt\test-more>cat footest.pl
use warnings;
use Foo;
use Test::More;
plan tests => 1;
$obj1 = Foo->new();
$obj2 = Foo->new();
@x = ($obj1, $obj2);
@y = ($obj1, $obj2);
ok(eq_array(\@x, \@y));
-----------------------
Running perl 5.8.8 with Test::More-0.64 we get:
----------------------
D:\pscrpt\test-more>perl -MTest::More -e "print $Test::More::VERSION"
0.64
D:\pscrpt\test-more>perl footest.pl
1..1
Foo Does::Not::Exist
Invalid object passed to overload_equiv
# Looks like your test died before it could output anything.
----------------------
With version 0.47 of Test::More (perl 5.8.6) there is no such problem:
----------------------
D:\pscrpt\test-more>\perl58_M\5.8.6\bin\perl -MTest::More -e "print
$Test::More::VERSION"
0.47
D:\pscrpt\test-more>\perl58_M\5.8.6\bin\perl footest.pl
1..1
equivalence overloaded
equivalence overloaded
ok 1
----------------------
The problem (in the Test-More-0.64 _deep_check subroutine) is caused by the
line:
elsif ( $e1 == $DNE xor $e2 == $DNE ) {
which needs to be replaced by something like:
elsif(UNIVERSAL::isa($e1, 'Does::Not::Exist') xor
UNIVERSAL::isa($e2,'Does::Not::Exist')) {
I find the same behaviour on both Win32 (Windows2000) and linux
(mandrake-9.1), perl 5.8.x.
Cheers,
Rob