]> git.ipfire.org Git - thirdparty/git.git/commitdiff
test-lib: check for leak logs after every test
authorJeff King <peff@peff.net>
Tue, 24 Sep 2024 21:38:36 +0000 (17:38 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 25 Sep 2024 17:23:01 +0000 (10:23 -0700)
If you are trying to find and fix leaks in a large test script, it can
be overwhelming to see the leak logs for every test at once. The
previous commit let you use "--immediate" to see the logs after the
first failing test, but this isn't always the first leak. As discussed
there, we may see leaks from previous tests that didn't happen to fail.

To catch those, let's check for any logs that appeared after each test
snippet is run, meaning that in a SANITIZE=leak build, any leak is an
immediate failure of the test snippet.

This check is mostly free in non-leak builds (just a "test -z"), and
only a few extra processes in a leak build, so I don't think the
overhead should matter (if it does, we could probably optimize for the
common "no logs" case without even spending a process).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/test-lib-functions.sh
t/test-lib.sh

index fde9bf54fc35fc3c8802cfa3af495ea71fcfd24f..78e054ab503a6573ca9810a19d89afff334c6ba2 100644 (file)
@@ -926,7 +926,8 @@ test_expect_success () {
                test_body_or_stdin test_body "$2"
                test -n "$test_skip_test_preamble" ||
                say >&3 "expecting success of $TEST_NUMBER.$test_count '$1': $test_body"
-               if test_run_ "$test_body"
+               if test_run_ "$test_body" &&
+                  check_test_results_san_file_empty_
                then
                        test_ok_ "$1"
                else
index d624ee186c878cd04b650f6b9d2b4efa88cf9af0..b1a8ee5c002b3572ba7eafee22ac08eeb3daf688 100644 (file)
@@ -1215,12 +1215,13 @@ test_atexit_handler () {
        teardown_malloc_check
 }
 
+check_test_results_san_file_empty_ () {
+       test -z "$TEST_RESULTS_SAN_FILE" ||
+       test "$(nr_san_dir_leaks_)" = 0
+}
+
 check_test_results_san_file_ () {
-       if test -z "$TEST_RESULTS_SAN_FILE"
-       then
-               return
-       fi &&
-       if test "$(nr_san_dir_leaks_)" = 0
+       if check_test_results_san_file_empty_
        then
                return
        fi &&