From 2966fbd39133870c1d6371ec84e902a6a18e3256 Mon Sep 17 00:00:00 2001 From: Paul Meyer Date: Fri, 14 Aug 2026 11:20:57 +0200 Subject: [PATCH] test: let subtests report skips via exit 77 run_subtests() and run_subtests_with_signals() now treat a subtest exit code of 77 as skipped rather than a failure, track skipped subtests separately, and list them in the summary. Previously a subtest could only fake a skip by exiting 0, which was indistinguishable from a real pass. Signed-off-by: Paul Meyer --- test/units/test-control.sh | 51 +++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/test/units/test-control.sh b/test/units/test-control.sh index 4546231d68..2c93382caf 100644 --- a/test/units/test-control.sh +++ b/test/units/test-control.sh @@ -8,6 +8,11 @@ fi declare -i _CHILD_PID=0 _PASSED_TESTS=() +_SKIPPED_TESTS=() + +# A subtest may exit with this code to report that it skipped itself, +# matching the skip code used by the integration test harness. +_SUBTEST_SKIP_RC=77 # Like trap, but passes the signal name as the first argument _trap_with_sig() { @@ -56,7 +61,7 @@ _wait_harder() { _show_summary() {( set +x - if [[ ${#_PASSED_TESTS[@]} -eq 0 ]]; then + if [[ ${#_PASSED_TESTS[@]} -eq 0 && ${#_SKIPPED_TESTS[@]} -eq 0 ]]; then echo >&2 "No tests were executed, this is most likely an error" exit 1 fi @@ -66,12 +71,34 @@ _show_summary() {( for t in "${_PASSED_TESTS[@]}"; do echo "$t" done + + if [[ ${#_SKIPPED_TESTS[@]} -gt 0 ]]; then + printf "SKIPPED TESTS: %3d:\n" "${#_SKIPPED_TESTS[@]}" + echo "-------------------" + for t in "${_SKIPPED_TESTS[@]}"; do + echo "$t" + done + fi )} +_record_subtest_rc() { + local subtest="${1:?}" rc="${2:?}" + + if [[ $rc -eq $_SUBTEST_SKIP_RC ]]; then + echo "Subtest $subtest skipped" + _SKIPPED_TESTS+=("$subtest") + elif [[ $rc -ne 0 ]]; then + echo "Subtest $subtest failed" + return 1 + else + _PASSED_TESTS+=("$subtest") + fi +} + # Like run_subtests, but propagate specified signals to the subtest script run_subtests_with_signals() { local subtests=("${0%.sh}".*.sh) - local subtest + local subtest rc if [[ "${#subtests[@]}" -eq 0 ]]; then echo >&2 "No subtests found for file $0" @@ -100,14 +127,11 @@ run_subtests_with_signals() { : "--- $subtest BEGIN ---" SECONDS=0 + rc=0 "./$subtest" & _CHILD_PID=$! - if ! _wait_harder "$_CHILD_PID"; then - echo "Subtest $subtest failed" - return 1 - fi - - _PASSED_TESTS+=("$subtest") + _wait_harder "$_CHILD_PID" || rc=$? + _record_subtest_rc "$subtest" "$rc" || return 1 : "--- $subtest END (${SECONDS}s) ---" done @@ -117,7 +141,7 @@ run_subtests_with_signals() { # Run all subtests (i.e. files named as $TESTNAME..sh) run_subtests() { local subtests=("${0%.sh}".*.sh) - local subtest + local subtest rc if [[ "${#subtests[@]}" -eq 0 ]]; then echo >&2 "No subtests found for file $0" @@ -139,12 +163,9 @@ run_subtests() { : "--- $subtest BEGIN ---" SECONDS=0 - if ! "./$subtest"; then - echo "Subtest $subtest failed" - return 1 - fi - - _PASSED_TESTS+=("$subtest") + rc=0 + "./$subtest" || rc=$? + _record_subtest_rc "$subtest" "$rc" || return 1 : "--- $subtest END (${SECONDS}s) ---" done