From ebedc6851ede12252b66b01e84bdb32315c9ac95 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 7 Nov 2026 08:28:51 -1000 Subject: Fail a test script that leaves a sanitizer report Without -v a report went to /dev/null with the rest of stderr, and one from a process whose status a pipeline or a background job loses failed nothing at all. --- tests/setup.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests/setup.sh') diff --git a/tests/setup.sh b/tests/setup.sh index bd8b4c4..68b7a5b 100644 --- a/tests/setup.sh +++ b/tests/setup.sh @@ -69,6 +69,37 @@ done unset cgit_variable umask 022 +# A sanitizer report goes to stderr, which the library throws away without -v, +# and a process whose exit status is lost, one in a pipeline say, fails no test +# at all. So each report is written to a file beside the script's counts, and +# any found there when the script ends are shown and fail a test of their own. +# The summary looks for them again. +cgit_sanitizer_log="$TEST_RESULTS_BASE.sanitizer" +mkdir -p "$TEST_RESULTS_DIR" && +rm -f "$cgit_sanitizer_log".* || + BAIL_OUT "cannot prepare $TEST_RESULTS_DIR for sanitizer reports" +ASAN_OPTIONS="$ASAN_OPTIONS:log_path='$cgit_sanitizer_log'" +UBSAN_OPTIONS="$UBSAN_OPTIONS:log_path='$cgit_sanitizer_log'" +export ASAN_OPTIONS UBSAN_OPTIONS + +# This runs when the script ends, where the library has pointed stdout and +# stderr at its verbose output, so they are pointed back for the test. It can +# run twice when -i stops the script, which the flag guards against. +cgit_check_sanitizer_logs() { + test -z "$cgit_sanitizer_checked" || return 0 + cgit_sanitizer_checked=t + set -- "$cgit_sanitizer_log".* + test -f "$1" || return 0 + cat "$@" >&7 + test_expect_success 'no sanitizer reported an error' ' + for cgit_sanitizer_report in "$cgit_sanitizer_log".* + do + test_path_is_missing "$cgit_sanitizer_report" || return 1 + done + ' >&5 2>&7 +} +test_atexit cgit_check_sanitizer_logs + # The library has moved into the trash directory by now, so paths outside it # are anchored to TEST_OUTPUT_DIRECTORY. The tests run cgit by name, so the # binary just built has to come ahead of any copy already installed. Under -- cgit 2.12.1