]> git.ipfire.org Git - thirdparty/git.git/commitdiff
tests(junit-xml): avoid invalid XML
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Mon, 23 Mar 2020 12:44:35 +0000 (12:44 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 23 Mar 2020 17:22:51 +0000 (10:22 -0700)
When a test case is run in a subshell, we finalize the JUnit-style XML
when said subshell exits. But then we continue to write into that XML as
if nothing had happened.

This leads to Azure Pipelines' Publish Test Results task complaining:

Failed to read /home/vsts/work/1/s/t/out/TEST-t0000-basic.xml.
Error : Unexpected end tag. Line 110, position 5.

And indeed, the resulting XML is incorrect.

Let's "re-open" the XML in such a case, i.e. remove the previously added
closing tags.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/test-lib.sh

index 0ea1e5a05edd86b3923cb82fd503b34ebbe93254..7f0c02c016be4dfeebc25205ca54b6b8707c33a8 100644 (file)
@@ -1085,6 +1085,7 @@ finalize_junit_xml () {
                junit_time=$(test-tool date getnanos $junit_suite_start)
                sed -e "s/\(<testsuite.*\) time=\"[^\"]*\"/\1/" \
                        -e "s/<testsuite [^>]*/& time=\"$junit_time\"/" \
+                       -e '/^ *<\/testsuite/d' \
                        <"$junit_xml_path" >"$junit_xml_path.new"
                mv "$junit_xml_path.new" "$junit_xml_path"