From: Jeff King Date: Tue, 27 Oct 2026 17:38:24 GMT Subject: [PATCH 5/8] t: run clar unit tests through test-lib.sh Message-ID: <20261027173824.GE136740@coredump.intra.peff.net> In-Reply-To: <20261027173205.GA97799@coredump.intra.peff.net> We run the clar unit-test binary directly, without going through test-lib.sh. This means it misses out on the setup done by the shell tests, and is inconsistent with the rest of the test suite. I've hit two specific cases in practice. One is that we accept but ignore --verbose-log. This means that if unit-tests fail in CI (which runs the tests under prove, eating their stdout), we never get to see the failing test output at all! Another is that test-lib.sh sets sanitizer options like LSAN_OPTIONS. You can see the difference by creating an intentional leak like this: diff --git a/t/unit-tests/u-strbuf.c b/t/unit-tests/u-strbuf.c index caa5d78aa3..4d252902ed 100644 --- a/t/unit-tests/u-strbuf.c +++ b/t/unit-tests/u-strbuf.c @@ -84,6 +84,8 @@ static void t_addstr(struct strbuf *buf, const void *data) size_t orig_alloc = buf->alloc; size_t orig_len = buf->len; + write(2, strdup("foo"), 3); + assert_sane_strbuf(buf); strbuf_addstr(buf, text); assert_sane_strbuf(buf); Without fast_unwind_on_malloc=0, you get a fairly useless report. With test-lib.sh's settings, we get the full stack trace. Obviously we could port these features into the unit-test code. But by wrapping them in a regular test script we get that for free, plus it will let us get rid of some extra complexities in our prove invocations (in subsequent patches). We do have to forward any relevant options to the unit-test binary. We should do that here in t0011 and not as a central test-lib.sh feature, because the set of handled options may differ between external programs (if we ever even get a second one). Right now we support --immediate and nothing else. In theory we should be able to handle --run, but the syntax is a bit different between the two systems. This is no worse than the existing behavior, though, since run-test.sh only passes GIT_TEST_OPTS to shell tests, not to the unit-test binary. Likewise we do not support --write-junit-xml; the unit-tests will run but the results won't be present in the XML output. It would be possible to support this with some work, but for now we are not making anything worse (the unit-tests are currently run separately and do not even support the option). One note on the implementation: we have to inform meson of the dependency. Without that, running "meson test t0011-unit-tests" would fail (but "meson compile" first would be OK, because it builds the unit tests). The make system doesn't have the same problem, because it just depends on "all" before testing (the meson equivalent would be depending on "compile", but it is more fine-grained). Signed-off-by: Jeff King --- t/meson.build | 3 +++ t/t0011-unit-tests.sh | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100755 t/t0011-unit-tests.sh diff --git a/t/meson.build b/t/meson.build index 11b3752f00..fc628ad2d1 100644 --- a/t/meson.build +++ b/t/meson.build @@ -76,6 +76,8 @@ clar_unit_tests = executable('unit-tests', ) test('unit-tests', clar_unit_tests, kwargs: test_kwargs) +test_dependencies += clar_unit_tests + subdir('helper') integration_tests = [ @@ -90,6 +92,7 @@ integration_tests = [ 't0008-ignores.sh', 't0009-git-dir-validation.sh', 't0010-racy-git.sh', + 't0011-unit-tests.sh', 't0012-help.sh', 't0013-sha1dc.sh', 't0014-alias.sh', diff --git a/t/t0011-unit-tests.sh b/t/t0011-unit-tests.sh new file mode 100755 index 0000000000..ac3d7ccda2 --- /dev/null +++ b/t/t0011-unit-tests.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +test_description='run clar unit tests' +test_external=t +. ./test-lib.sh + +# We store the binary in different locations for make vs meson. Yuck. +if test -d "$GIT_BUILD_DIR/t/unit-tests" +then + UNIT_TESTS="$GIT_BUILD_DIR/t/unit-tests/bin/unit-tests" +else + UNIT_TESTS="$GIT_BUILD_DIR/t/unit-tests" +fi + +# Pass along any options that are meaningful to the unit-test binary here. +"$UNIT_TESTS" \ + ${immediate:+-i} \ + || error "unit-test binary failed" + +test_done -- 2.56.0.559.g7c1a1d8168