Thread (9 messages) 9 messages, 1 author, 3d ago

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

flat view
WARM3d

From: Jeff King <hidden>
Date: 2026-10-27 17:35:28
Subsystem: the rest · Maintainer: Linus Torvalds

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 <redacted>
---
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help