kward / shunit2

shUnit2 is a xUnit based unit test framework for Bourne based shell scripts.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Failure is double counted

xuyuji9000 opened this issue · comments

Testing shell:
GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)

Testing script:

#! /bin/sh
# file: examples/equality_test.sh

testEquality() {
  assertEquals 1 1
}

testEquality2() {
  assertEquals 1 2
}


. ../shunit2

Output:

[root@67087c3bc37c tmp]# ./test.sh 
testEquality
testEquality2
ASSERT:expected:<1> but was:<2>
shunit2:ERROR testEquality2() returned non-zero return code.

Ran 2 tests.

FAILED (failures=2)

There should be only ONE failure, but the actually failures count is TWO.

Found the reason:

shunit2/shunit2

Lines 1089 to 1124 in ebc4baa

_shunit_execSuite() {
for _shunit_test_ in ${__shunit_suite}; do
__shunit_testSuccess=${SHUNIT_TRUE}
# Disable skipping.
endSkipping
# Execute the per-test setup function.
if ! setUp; then
_shunit_fatal "setup() returned non-zero return code."
fi
# Execute the test.
echo "${__SHUNIT_TEST_PREFIX}${_shunit_test_}"
# shellcheck disable=SC2086
if ! eval ${_shunit_test_}; then
_shunit_error "${_shunit_test_}() returned non-zero return code."
__shunit_testSuccess=${SHUNIT_ERROR}
_shunit_incFailedCount
fi
# Execute the per-test tear-down function.
if ! tearDown; then
_shunit_fatal "tearDown() returned non-zero return code."
fi
# Update stats.
if ${__SHUNIT_BUILTIN} [ ${__shunit_testSuccess} -eq ${SHUNIT_TRUE} ]; then
__shunit_testsPassed=`expr ${__shunit_testsPassed} + 1`
else
__shunit_testsFailed=`expr ${__shunit_testsFailed} + 1`
fi
done
unset _shunit_test_
}

and

shunit2/shunit2

Lines 1199 to 1206 in ebc4baa

_shunit_assertFail() {
__shunit_testSuccess=${SHUNIT_FALSE}
_shunit_incFailedCount
if ${__SHUNIT_BUILTIN} [ $# -gt 0 ]; then
${__SHUNIT_CMD_ECHO_ESC} "${__shunit_ansi_red}ASSERT:${__shunit_ansi_none}$*"
fi
}

Increased __shunit_assertsFailed twice

Thank you for your contribution!