Skip to content

running unit tests inside a test-lib script

Jeff King git 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest8 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/8unit-tests: report the correct unexpected argumentt/unit-tests/unit-test.c+1 -10 replies
2/8test-lib: drop unused test_external_has_tap variablet/test-lib.sh+0 -20 replies
3/8test-lib: stop inventing a JUnit testcase for empty suitest/test-lib-junit.sh+0 -70 replies
4/8test-lib: allow an external program to supply TAP outputt/test-lib.sh+6 -30 replies
5/8t: run clar unit tests through test-lib.sht/meson.build t/t0011-unit-tests.sh+23 -00 replies
6/8t: drop redundant unit-test invocationsci/run-test-slice.sh t/Makefile t/meson.build +1 more+2 -340 replies
7/8test-tool: drop the run-command testsuite modet/helper/test-run-command.c+0 -1730 replies
8/8test-lib: drop the shell JUnit XML reporting codeMakefile t/helper/meson.build t/helper/test-tool.c +4 more+1 -2130 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/8] running unit tests inside a test-lib script

I saw a unit-test failure in CI a while back, and much to my annoyance it was quite hard to debug, because we don't report the unit-test output at all!

The problem is that we feed the unit-test binary to prove, which eats the TAP output it produces. Normal tests get around this by using --verbose-log (and then CI dumps the log). But the unit-test script silently ignores that option, and you get no feedback at all about which test failed.

We could fix that, obviously, but I think it's a symptom of a larger
problem: we don't do the usual setup things that test-lib.sh does. Another example I found in the real world is that we skip some environment setup, like LSAN_OPTIONS, leading to worse output for some leaks. I'd guess there are other cases, as well.

So the real goal of this series is patch 5, which just lets us wrap the unit-test binary in a regular t0001-unit-tests.sh script. Patch 4 is the test-lib.sh tweaks needed for this.

And naturally, the whole thing turned up a few bugs, which are fixed in patches 1-3. But it also turned up a number of cleanup possibilities. The diffstat is very satisfying, but note the final two which I've marked as RFC.

This would also avoid the need for the unit-tests to ignore test-lib options, like the patches we saw recently in:

https://lore.kernel.org/git/20261026-ks-unit-tests-ignore-long-tests-v2-0-fdbbefbd19fb@gmail.com/

I didn't clean up the existing ignored ones here, but I think it would probably be reasonable to do so.

[1/8]: unit-tests: report the correct unexpected argument [2/8]: test-lib: drop unused test_external_has_tap variable [3/8]: test-lib: stop inventing a JUnit testcase for empty suites [4/8]: test-lib: allow an external program to supply TAP output [5/8]: t: run clar unit tests through test-lib.sh [6/8]: t: drop redundant unit-test invocations
[7/8]: test-tool: drop the run-command testsuite mode [8/8]: test-lib: drop the shell JUnit XML reporting code

 Makefile                    |   1 -
 ci/run-test-slice.sh        |   5 --
 t/Makefile                  |  12 +--
 t/helper/meson.build        |   1 -
 t/helper/test-run-command.c | 173 ------------------------------------
 t/helper/test-tool.c        |   1 -
 t/helper/test-tool.h        |   1 -
 t/helper/test-xml-encode.c  |  80 -----------------
 t/meson.build               |   4 +-
 t/run-test.sh               |  18 ----
 t/t0011-unit-tests.sh       |  20 +++++
 t/test-lib-junit.sh         | 132 ---------------------------
 t/test-lib.sh               |  16 ++--
 t/unit-tests/unit-test.c    |   2 +-
 14 files changed, 33 insertions(+), 433 deletions(-)
 delete mode 100644 t/helper/test-xml-encode.c
 delete mode 100755 t/run-test.sh
 create mode 100755 t/t0011-unit-tests.sh
 delete mode 100644 t/test-lib-junit.sh