| Issue 36: | cmp_ok($foo, "ne", "") gives the wrong expected value | |
| 2 people starred this issue and may be notified of changes. | Back to list |
Sign in to add a comment
|
What steps will reproduce the problem? 1. $foo = undef; cmp_ok($foo, "ne", ""); What is the expected output? # Failed test at -e line 1. # got: undef # expected: anything but "" That would be a start, but it loses the fact that this is an "ne" test. So this would be better: # Failed test at -e line 1. # undef ne "" What do you see instead? # Failed test at -e line 1. # got: undef # expected: anything else |
||||||||||
,
Feb 20, 2009
Is this to be a special case for undef, or should it apply to all 'isnt' comparisons? If the latter, should it apply to 'is' comparisons as well? |
|||||||||||
,
Feb 20, 2009
It will occur any time the thing on the left and right are not the same, and yet are
still equal. Another example is 0 and 0.0.
$ perl -wle 'use Test::More test => 1; cmp_ok("0", "!=", "0.0")'
1..1
not ok 1
# Failed test at -e line 1.
# got: 0
# expected: anything else
# Looks like you failed 1 test of 1.
We got 0 but we expected 0.0.
The problem with the isnt() diagnostics is that it assumes that on failure what we
got is the same as what we expected. is() does not have this problem because it
shows what we got and what we expected.
|
|||||||||||
,
Feb 22, 2009
Makes sense. I've fixed this in http://github.com/gaurav/test-more/tree/issue36, but, since 'cmp_ok' throws a warning when 'undef' values are used, my new test produces these warnings as well. Should I use $SIG{__WARN__} to surpress these warning messages, or fix 'cmp_ok' to handle 'undef' correctly? I tried to do the latter, but t/undef.t specifically checks for that warning, and I didn't want to break it in case somebody depends on it. |
|||||||||||
|
|
|||||||||||