#3 assert() params are reversed - very bad


Summary: When the condition is blank (empty string), the test will pass although it shouldn't.

JUnit 3.5 has
assert(message, condition);

perlUnit .13 has
assert(condition, message);

There's a problem with empty string parameters and that's probably why the parameters were
reversed. However, I ran into the problem using the current order.

Using the fail-example provided, the test that fails is "born" =~ /loose/.
assert("born" =~ /loose/, "Born to lose ...");
For some reason this works as expected.
However, the following doesn't (the Test::Unit::TestCase variation):
$self->assert("born" =~ /loose/, "Born to lose ...");
but this will:
$self->assert(scalar "born" =~ /loose/, "Born to lose ...");

The doc for m// states "if there is no match, a false value ("") is returned". This being an empty
string results in only the message being passed as a parameter which is always true and so the
test doesn't fail as it should.

Anyway, this is a bad situation. Maybe assert should have a prototype requiring two params? If the
condition is second the test will always fail if no message is given. I think this is preferable to the
current state where the test will pass if there's an empty condition and a given message when it
should fail.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks