Skip to content

Commit

Permalink
Fixed failing tests, and fixed issue #129.
Browse files Browse the repository at this point in the history
  • Loading branch information
kward committed Mar 29, 2020
1 parent 45b1961 commit 59afbdc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
16 changes: 7 additions & 9 deletions shunit2
Original file line number Diff line number Diff line change
Expand Up @@ -480,17 +480,16 @@ assertTrue() {

# See if condition is an integer, i.e. a return value.
shunit_return=${SHUNIT_TRUE}
shunit_match_=`expr "${shunit_condition_}" : '\([0-9]*\)'`
if (command [ -z "${shunit_condition_}" ]); then
# Null condition.
shunit_return=${SHUNIT_FALSE}
elif (command [ -n "${shunit_match_}" -a "${shunit_condition_}" = "${shunit_match_}" ])
elif (expr \( "${shunit_condition_}" + '0' \) '=' "${shunit_condition_}" >/dev/null 2>&1)
then
# Possible return value. Treating 0 as true, and non-zero as false.
(command [ "${shunit_condition_}" -ne 0 ]) && shunit_return=${SHUNIT_FALSE}
else
# Hopefully... a condition.
( eval "${shunit_condition_}" ) >/dev/null 2>&1
(eval "${shunit_condition_}" >/dev/null 2>&1)
(command [ $? -ne 0 ]) && shunit_return=${SHUNIT_FALSE}
fi

Expand All @@ -501,7 +500,7 @@ assertTrue() {
_shunit_assertFail "${shunit_message_}"
fi

unset shunit_message_ shunit_condition_ shunit_match_
unset shunit_message_ shunit_condition_
return ${shunit_return}
}
# shellcheck disable=SC2016,SC2034
Expand Down Expand Up @@ -546,18 +545,17 @@ assertFalse() {
shunit_condition_=$1

# See if condition is an integer, i.e. a return value.
shunit_match_=`expr "${shunit_condition_}" : '\([0-9]*\)'`
shunit_return=${SHUNIT_TRUE}
if (command [ -z "${shunit_condition_}" ]); then
# Null condition.
shunit_return=${SHUNIT_FALSE}
elif (command [ -n "${shunit_match_}" -a "${shunit_condition_}" = "${shunit_match_}" ])
shunit_return=${SHUNIT_TRUE}
elif (expr \( "${shunit_condition_}" + '0' \) '=' "${shunit_condition_}" >/dev/null 2>&1)
then
# Possible return value. Treating 0 as true, and non-zero as false.
(command [ "${shunit_condition_}" -eq 0 ]) && shunit_return=${SHUNIT_FALSE}
else
# Hopefully... a condition.
( eval "${shunit_condition_}" ) >/dev/null 2>&1
(eval "${shunit_condition_}" >/dev/null 2>&1)
(command [ $? -eq 0 ]) && shunit_return=${SHUNIT_FALSE}
fi

Expand All @@ -568,7 +566,7 @@ assertFalse() {
_shunit_assertFail "${shunit_message_}"
fi

unset shunit_message_ shunit_condition_ shunit_match_
unset shunit_message_ shunit_condition_
return "${shunit_return}"
}
# shellcheck disable=SC2016,SC2034
Expand Down
4 changes: 2 additions & 2 deletions shunit2_asserts_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ testAssertTrue() {
th_assertFalseWithOutput 'false condition' $? "${stdoutF}" "${stderrF}"

( assertTrue '' >"${stdoutF}" 2>"${stderrF}" )
th_assertFalseWithOutput 'null' $? "${stdoutF}" "${stderrF}"
th_assertFalseWithOutput 'null condition' $? "${stdoutF}" "${stderrF}"

( assertTrue >"${stdoutF}" 2>"${stderrF}" )
th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}"
Expand All @@ -237,7 +237,7 @@ testAssertFalse() {
th_assertFalseWithOutput 'true condition' $? "${stdoutF}" "${stderrF}"

( assertFalse '' >"${stdoutF}" 2>"${stderrF}" )
th_assertFalseWithOutput 'true condition' $? "${stdoutF}" "${stderrF}"
th_assertTrueWithNoOutput 'null condition' $? "${stdoutF}" "${stderrF}"

( assertFalse >"${stdoutF}" 2>"${stderrF}" )
th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}"
Expand Down

0 comments on commit 59afbdc

Please sign in to comment.