From f028cd4fd6efe9bb9c4b48cd5883e4eaa6d618d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 15 Jan 2025 13:08:07 +0100 Subject: [PATCH] Improve test output for failed stubs --- test/stubs/stub | 10 +++++++--- test/test_helper.bash | 8 ++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/test/stubs/stub b/test/stubs/stub index b9f7719d93..a0cd75a664 100755 --- a/test/stubs/stub +++ b/test/stubs/stub @@ -14,8 +14,8 @@ _STUB_RESULT="${PROGRAM}_STUB_RESULT" _STUB_END="${PROGRAM}_STUB_END" _STUB_DEBUG="${PROGRAM}_STUB_DEBUG" -if [ -n "${!_STUB_DEBUG}" ]; then - echo "$program" "$@" >&${!_STUB_DEBUG} +if [ -n "${!_STUB_DEBUG}" ] && [ -z "${!_STUB_END}" ]; then + echo stub: "$program" "$@" >&${!_STUB_DEBUG} fi [ -e "${!_STUB_PLAN}" ] || exit 1 @@ -25,9 +25,11 @@ fi # Initialize or load the stub run information. eval "${_STUB_INDEX}"=1 eval "${_STUB_RESULT}"=0 +# shellcheck disable=SC1090 [ ! -e "${!_STUB_RUN}" ] || source "${!_STUB_RUN}" # Expose this for stub scripts. +# shellcheck disable=SC2317 inspect_args() { local arg local sep='' @@ -101,9 +103,11 @@ if [ -n "${!_STUB_END}" ]; then # Clean up the run file. rm -f "${!_STUB_RUN}" + stub_index_value="${!_STUB_INDEX}" # If the number of lines in the plan is larger than # the requested index, we failed. - if [ $index -ge "${!_STUB_INDEX}" ]; then + if [ "$index" -ge "$stub_index_value" ]; then + echo "$program: expected $index invocations, got $((stub_index_value-1))" >&2 eval "${_STUB_RESULT}"=1 fi diff --git a/test/test_helper.bash b/test/test_helper.bash index 6a7792909f..2caac444e1 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -66,9 +66,17 @@ unstub() { export "${prefix}_STUB_END"=1 + local stub_was_invoked= + [ -e "${TMP}/${program}-stub-run" ] && stub_was_invoked=1 + local STATUS=0 "$path" || STATUS="$?" + local debug_var="${prefix}_STUB_DEBUG" + if [ $STATUS -ne 0 ] && [ -z "${!debug_var}" ] && [ -n "$stub_was_invoked" ]; then + echo "unstub $program: re-run test with ${debug_var}=3 to log \`$program' invocations" >&2 + fi + rm -f "$path" rm -f "${TMP}/${program}-stub-plan" "${TMP}/${program}-stub-run" return "$STATUS"