diff --git a/shunit2_misc_test.sh b/shunit2_misc_test.sh index 5426731..c855e34 100755 --- a/shunit2_misc_test.sh +++ b/shunit2_misc_test.sh @@ -27,20 +27,7 @@ stderrF="${TMPDIR:-/tmp}/STDERR" # Note: the test script is prefixed with '#' chars so that shUnit2 does not # incorrectly interpret the embedded functions as real functions. testUnboundVariable() { - unittestF="${SHUNIT_TMPDIR}/unittest" - sed 's/^#//' >"${unittestF}" <"${stdoutF}" 2>"${stderrF}" ) assertFalse 'expected a non-zero exit value' $? grep '^ASSERT:unknown failure' "${stdoutF}" >/dev/null @@ -69,14 +56,7 @@ EOF # Support prefixes on test output. # https://github.com/kward/shunit2/issues/29 testIssue29() { - unittestF="${SHUNIT_TMPDIR}/unittest" - sed 's/^#//' >"${unittestF}" <"${stdoutF}" 2>"${stderrF}" ) grep '^--- test_assert' "${stdoutF}" >/dev/null rtrn=$? @@ -123,21 +103,10 @@ EOF # Ensure a test failure is recorded for code containing syntax errors. # https://github.com/kward/shunit2/issues/84 testIssue84() { - unittestF="${SHUNIT_TMPDIR}/unittest" - sed 's/^#//' >"${unittestF}" <<\EOF -## Function with syntax error. -#syntax_error() { ${!#3442} -334 a$@2[1]; } -#test_syntax_error() { -# syntax_error -# assertTrue ${SHUNIT_TRUE} -#} -#SHUNIT_COLOR='none' -#SHUNIT_TEST_PREFIX='--- ' -#. ${TH_SHUNIT} -EOF + unittestF=tests/data/testIssue84.sh ( exec "${SHELL:-sh}" "${unittestF}" >"${stdoutF}" 2>"${stderrF}" ) grep '^FAILED' "${stdoutF}" >/dev/null - assertTrue "failure message for ${assert} was not generated" $? + assertTrue "failure message for syntax error was not generated" $? } testPrepForSourcing() { diff --git a/test_runner b/test_runner index 07a423d..e8d5456 100755 --- a/test_runner +++ b/test_runner @@ -159,7 +159,7 @@ EOF echo "--- Executing the '`_runner_testName "${t}"`' test suite. ---" # ${shell_bin} needs word splitting. # shellcheck disable=SC2086 - ( exec ${shell_bin} "./${t}" 2>&1; ) + ( SHELL="${shell_bin}" exec ${shell_bin} "./${t}" 2>&1; ) test "${runner_passing_}" -eq ${RUNNER_TRUE} -a $? -eq ${RUNNER_TRUE} runner_passing_=$? done diff --git a/tests/data/testIssue29.sh b/tests/data/testIssue29.sh new file mode 100755 index 0000000..625c761 --- /dev/null +++ b/tests/data/testIssue29.sh @@ -0,0 +1,5 @@ +# Support test prefixes. +test_assert() { assertTrue ${SHUNIT_TRUE}; } +SHUNIT_COLOR='none' +SHUNIT_TEST_PREFIX='--- ' +. ${TH_SHUNIT} diff --git a/tests/data/testIssue84.sh b/tests/data/testIssue84.sh new file mode 100755 index 0000000..547e61c --- /dev/null +++ b/tests/data/testIssue84.sh @@ -0,0 +1,9 @@ +# Function with syntax error. +syntax_error() { ${!#3442} -334 a$@2[1]; } +test_syntax_error() { + syntax_error + assertTrue ${SHUNIT_TRUE} +} +SHUNIT_COLOR='none' +SHUNIT_TEST_PREFIX='--- ' +. ${TH_SHUNIT} diff --git a/tests/data/testUnboundVariable.sh b/tests/data/testUnboundVariable.sh new file mode 100755 index 0000000..abfc42c --- /dev/null +++ b/tests/data/testUnboundVariable.sh @@ -0,0 +1,11 @@ +# Treat unset variables as an error when performing parameter expansion. +set -u + +boom() { x=$1; } # This function goes boom if no parameters are passed! +test_boom() { + assertEquals 1 1 + boom # No parameter given + assertEquals 0 $? +} +SHUNIT_COLOR='none' +. "${TH_SHUNIT}"