I observed that the following functions are not working properly in the 2.0 version of shUnit2 (and probably in 2.1 either):
- failNotEquals
- failSame
- failNotSame
AFAIK, failNotEquals should fail when given parameters are not equal so passing '1' and '0' should fail, while '1' and '1' should not. However I always get failure, regardless of the parameters:
ASSERT:fail: not equals expected:<1> but was:<1>
ASSERT:fail: not equals expected:<1> but was:<0>
Same happens with testFailSame. This is what I tried...
failSame "failSame FAILED" "text" "text"
failSame "failSame FAILED" "text" "not same text"
...and this is what I got:
ASSERT:failSame FAILED expected not same
ASSERT:failSame FAILED expected not same
And, at last, same happens with testFailNotSame. I tried this...
failNotSame "failNotSame FAILED" "text" "text"
failNotSame "failNotSame FAILED" "text" "not same text"
...and I got this:
ASSERT:failNotSame FAILED expected:<text> but was:<text>
ASSERT:failNotSame FAILED expected:<text> but was:<not same text>
Perhaps I'm misunderstanding something, but I imagine this could be a bug, so here you are the report. If not, I'd be very happy to know why, so I could understand the desired behaviour better, so thanks in advance ;-)
Otherwise, please take a look into the patch I'm attaching (done against 2.0.4 version of shunit2), I'm using it right now and it seems to work fine :-)
Patch that could fix the bug
Logged In: NO
Sorry, the attached patch is wrong, the right one would be this one:
diff --git a/source/2.0/src/shell/shunit2 b/source/2.0/src/shell/shunit2
index 097621e..8f3be17 100644
--- a/source/2.0/src/shell/shunit2
+++ b/source/2.0/src/shell/shunit2
@@ -403,7 +403,12 @@ failNotEquals()
_su_unexpected=${1:-}
_su_actual=${2:-}
- _shunit_testFailed "${_su_message:+${_su_message} }expected:<${_su_unexpected}> but was:<${_su_actual}>"
+ shunit_return=${__SHUNIT_TRUE}
+ if [ "${_su_unexpected}" = "${_su_actual}" ]; then
+ _shunit_testPassed
+ else
+ _shunit_testFailed "${_su_message:+${_su_message} }expected:<${_su_unexpected}> but was:<${_su_actual}>"
+ fi
unset _su_message _su_unexpected _su_actual
}
@@ -427,11 +432,22 @@ failNotEquals()
#*/
failSame()
{
- _su_message=${1:-}
+ _su_message=''
+ if [ $# -eq 3 ]; then
+ _su_message=$1
+ shift
+ fi
+ _su_expected=${1:-}
+ _su_actual=${2:-}
- _shunit_testFailed "${_su_message:+${_su_message} }expected not same"
+ shunit_return=${__SHUNIT_TRUE}
+ if [ "${_su_expected}" = "${_su_actual}" ]; then
+ _shunit_testPassed
+ else
+ _shunit_testFailed "${_su_message:+${_su_message} }expected not same"
+ fi
- unset _su_message
+ unset _su_message _su_expected _su_actual
}
#/**