Skip Menu |

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

Report information
The Basics
Id: 16125
Status: open
Priority: 0/
Queue: Test-Unit

Owner: mca1001 [...]
Requestors: guido [...]

Bug Information
Severity: Normal
Broken in: 0.25
Fixed in: (no value)

Subject: Assertions on hash references do not work
Download (untitled) / with headers
text/plain 648b
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
Download (untitled) / with headers
text/plain 1.3k
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 is sponsored and maintained by Best Practical Solutions and runs on infrastructure.

Please report any issues with to