mascip has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
i wrote a test with
But am quite annoyed, as the test passes when the (unimplemented) subroutine returns 'undef'.my $score = result_of_a_function(); cmp_ok($score, '==', 0, 'scores 0 in blablabla context');
it doesn't display anything. If it displayed 0, i would probably be quite happy.print $score;
undef==0, it's a feature of the language, i have to accept it and adapt. Which is very simple: when i want to test that a value is 0, i can just use
There are good reasons for this choice, it is sometimes very handy to use strings or numbers in each other's place.is($score, 0, 'scores 0 in blablabla context');
EDIT : the problem was wider than i thought :
also returns true. Which means that any1>undef
statement runs into the same risk / problem.cmp_ok($got, '<', $expected)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: 0==undef, that's annoying. Is it?
by tobyink (Canon) on Jul 15, 2012 at 21:56 UTC | |
by mascip (Pilgrim) on Jul 15, 2012 at 22:41 UTC | |
by AnomalousMonk (Archbishop) on Jul 15, 2012 at 23:11 UTC | |
by Anonymous Monk on Jul 15, 2012 at 23:33 UTC | |
|
Re: 0==undef, that's annoying. Is it?
by GrandFather (Saint) on Jul 16, 2012 at 02:57 UTC | |
by mascip (Pilgrim) on Jul 16, 2012 at 11:24 UTC | |
by mascip (Pilgrim) on Jul 19, 2012 at 12:51 UTC | |
|
Re: 0==undef, that's annoying. Is it?
by Marshall (Canon) on Jul 16, 2012 at 06:42 UTC | |
|
Re: 0==undef, that's annoying. Is it?
by AnomalousMonk (Archbishop) on Jul 15, 2012 at 22:38 UTC | |
by mascip (Pilgrim) on Jul 15, 2012 at 22:43 UTC |