test-lib: invert return value of check_test_results_san_file_empty

We have a function to check whether LSan logged any leaks. It returns success for no leaks, and non-zero otherwise. This is the simplest thing for its callers, who want to say "if no leaks then return early". But because it's implemented as a shell pipeline, you end up with the awkward: ! find ... | xargs grep leaks | grep -v false-positives where the "!" is actually negating the final grep. Switch the return value (and name) to return success when there are leaks. This should make the code a little easier to read, and the negation in the callers still reads pretty naturally. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jan 7, 2025 at 02:05 UTC 8d24d56ce1da13caff82cfa8950413309e08da13
2 files changed +5 -5
t/test-lib-functions.sh
+1 -1
@@ -927,7 +927,7 @@ test_expect_success () {
927 test -n "$test_skip_test_preamble" ||
928 say >&3 "expecting success of $TEST_NUMBER.$test_count '$1': $test_body"
929 if test_run_ "$test_body" &&
930 - check_test_results_san_file_empty_
930 + ! check_test_results_san_file_has_entries_
931 then
932 test_ok_ "$1"
933 else
t/test-lib.sh
+4 -4
@@ -1169,12 +1169,12 @@ test_atexit_handler () {
1169 teardown_malloc_check
1170 }
1171
1172 -check_test_results_san_file_empty_ () {
1173 - test -z "$TEST_RESULTS_SAN_FILE" && return 0
1172 +check_test_results_san_file_has_entries_ () {
1173 + test -z "$TEST_RESULTS_SAN_FILE" && return 1
1174
1175 # stderr piped to /dev/null because the directory may have
1176 # been "rmdir"'d already.
1177 - ! find "$TEST_RESULTS_SAN_DIR" \
1177 + find "$TEST_RESULTS_SAN_DIR" \
1178 -type f \
1179 -name "$TEST_RESULTS_SAN_FILE_PFX.*" 2>/dev/null |
1180 xargs grep ^DEDUP_TOKEN |
@@ -1182,7 +1182,7 @@ check_test_results_san_file_empty_ () {
1182 }
1183
1184 check_test_results_san_file_ () {
1185 - if check_test_results_san_file_empty_
1185 + if ! check_test_results_san_file_has_entries_
1186 then
1187 return
1188 fi &&