This queue is for tickets about the Test-Unit CPAN distribution.

Report information
The Basics

mca1001 [...]
guido [...]

Broken in:
Fixed in:
(no value)

Subject: Assertions on hash references do not work
The following code in a test: my $hashref = {}; $self->assert ($hashref); will fail with: can't call method "can" on unblessed reference. Variant: my $scalarref = \"foobar"; $self->assert ($scalarref); will fail with: Don't know how to normalize SCALAR(0x85dd580) (ref SCALAR) The first case is a bug, the second IMHO a nuisance. The "normalization" is a surprising feature, and not really helpful. Besides, the documentation seems to divert from the implementation in Test::Unit::Assert. My expectation was that assert() would succeed if its first argument evaluates to a truth value. It's Perl after all. Regards, Guido
Subject: assert() is heavily overloaded
The T:U:Assert->assert method is overloaded to do various things depending on the first argument. The behaviour on HASH ref isn't useful ... and the documentation doesn't explain what's going on. The fundamental problem with the assert method is that we don't get the benefit of prototypes to assist with scalar vs. list context, and we don't get language support for spiffy overloading so it's done by hand - in this case with no check for blessedness. I would like to give this area some serious attention, but that will have to be "later". For now, I believe the best solution is to mark the assert method with "here be dragon". It has bitten people various ways, so for now it may be better to write exactly what you mean, $self->fail("wanted true") if !$hashref; $self->fail("wanted plain hash") if ref($hashref) ne "HASH"; For completeness, I mention the worst problem $self->assert($str =~ /regexp/, "did not match"); # WRONG $self->assert(scalar $str =~ /regexp/, "did not match"); # works ok $self->fail("did not match") unless $str =~ /regexp/; # works ok $self->assert(qr/regexp/, $str, "did not match"); # official version and the complaint about parameters being the wrong way around, Sourceforge bug #407833

This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with to