git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/8] test-lib: stop inventing a JUnit testcase for empty suites

From
Jeff King <peff@peff.net>
Date
Oct 27, 2026, 17:35 UTC
Message-ID
<20261027173525.GC136740@coredump.intra.peff.net>
In-Reply-To
<20261027173205.GA97799@coredump.intra.peff.net>

If a script finishes without reporting any test cases, the JUnit output code tries to call write_junit_xml_testcase(). But that function went away in 78d5e4cfb4 (tests: refactor --write-junit-xml code, 2022-05-21), so we get a shell error instead. A script which sets skip_all and calls test_done without running any tests is enough to trigger this. For example, on Linux:

  $ ./t0051-windows-named-pipe.sh --write-junit-xml
  ./t0051-windows-named-pipe.sh: 97: write_junit_xml_testcase: not found
  1..0 # SKIP skipping Windows-specific tests

This is mostly an annoyance, but it gets even worse with the "set -e" detector:

  $ GIT_TEST_USE_SET_E=1 ./t0051-windows-named-pipe.sh --write-junit-xml
  ./t0051-windows-named-pipe.sh: 97: write_junit_xml_testcase: not found
  FATAL: Unexpected exit with code 127

Before the refactoring in that commit, the fallback wrote a successful testcase named "all tests skipped". We could resurrect that, but I'm not sure it actually makes sense. We can just leave the suite empty if we don't have any testcases to report.

This also prepares us for scripts which delegate TAP output to an external program. We can't report those as JUnit XML (we don't know what was in the TAP!), but it does prevent us from inventing fake results or complaining about the missing function.

Signed-off-by: Jeff King <peff@peff.net>
---
I do propose dropping the JUnit support entirely in the final patch, but
this is the minimum needed to unblock the rest of the series in the
meantime (in case we do want to keep it).
 t/test-lib-junit.sh | 7 -------
 1 file changed, 7 deletions(-)
diff --git a/t/test-lib-junit.sh b/t/test-lib-junit.sh
index f4994dd9d3..03a7360198 100644
--- a/t/test-lib-junit.sh
+++ b/t/test-lib-junit.sh
@@ -86,17 +86,11 @@ finalize_test_case_output () {
 		date getnanos $junit_start)\""
 	write_junit_xml "$(printf '%s\n' \
 		"    <testcase $junit_attrs>" "$@" "    </testcase>")"
-	junit_have_testcase=t
 }
 
 finalize_test_output () {
 	if test -n "$junit_xml_path"
 	then
-		test -n "$junit_have_testcase" || {
-			junit_start=$(test-tool date getnanos)
-			write_junit_xml_testcase "all tests skipped"
-		}
-
 		# adjust the overall time
 		junit_time=$(test-tool date getnanos $junit_suite_start)
 		sed -e "s/\(<testsuite.*\) time=\"[^\"]*\"/\1/" \
@@ -114,7 +108,6 @@ write_junit_xml () {
 	case "$1" in
 	--truncate)
 		>"$junit_xml_path"
-		junit_have_testcase=
 		shift
 		;;
 	esac
-- 
2.56.0.559.g7c1a1d8168
Previous: Jeff KingNext: Jeff King
Message 4 of 9 in “running unit tests inside a test-lib script”
  1. 0/8 running unit tests inside a test-lib scriptJeff King, Oct 27, 2026
  2. 1/8 unit-tests: report the correct unexpected argumentJeff King, Oct 27, 2026
  3. 2/8 test-lib: drop unused test_external_has_tap variableJeff King, Oct 27, 2026
  4. 3/8 test-lib: stop inventing a JUnit testcase for empty suitesJeff King, Oct 27, 2026
  5. 4/8 test-lib: allow an external program to supply TAP outputJeff King, Oct 27, 2026
  6. 5/8 t: run clar unit tests through test-lib.shJeff King, Oct 27, 2026
  7. 6/8 t: drop redundant unit-test invocationsJeff King, Oct 27, 2026
  8. 7/8 test-tool: drop the run-command testsuite modeJeff King, Oct 27, 2026
  9. 8/8 test-lib: drop the shell JUnit XML reporting codeJeff King, Oct 27, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.