Skip to contentSkip to conversation

tests(junit-xml): avoid invalid XML

PATCH In review Johannes Schindelin via GitGitGadget 3 participants 3 messages Mar 23, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests(junit-xml): avoid invalid XML

From: Johannes Schindelin <[email protected]>

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.

---
Fix Azure Pipelines for t0000

When running t0000 in our Azure Pipeline, the "Publish Test Results" step complains about an invalid JUnit-style XML, and it is correct. Let's fix that.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-732%2Fdscho%2Fci-xml-error-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-732/dscho/ci-xml-error-v1
Pull-Request: https://github.com/git/git/pull/732

 t/test-lib.sh | 1 +
 1 file changed, 1 insertion(+)
t/test-lib.sh +1 -0
index 0ea1e5a05ed..7f0c02c016b 100644
@@ -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"
 

base-commit: be8661a3286c67a5d4088f4226cbd7f8b76544b0

Signature · 1 line
gitgitgadget
#1 lore raw

"Johannes Schindelin via GitGitGadget" <[email protected]>

Quoted 16 lines · writes:

From: Johannes Schindelin <[email protected]>

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.

Quoted 7 lines

---
Fix Azure Pipelines for t0000

When running t0000 in our Azure Pipeline, the "Publish Test Results" step complains about an invalid JUnit-style XML, and it is correct. Let's fix that.

Hmph, I have a vague recollection that I've seen this one, looked at the patch and even understood the issue. Did I then forget to apply it back then? If so, apologies for failing to do so before the release.

Will queue.

Thanks.

Quoted 21 lines

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-732%2Fdscho%2Fci-xml-error-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-732/dscho/ci-xml-error-v1
Pull-Request: https://github.com/git/git/pull/732

 t/test-lib.sh | 1 +
 1 file changed, 1 insertion(+)
t/test-lib.sh +1 -0
index 0ea1e5a05ed..7f0c02c016b 100644
@@ -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"
 

base-commit: be8661a3286c67a5d4088f4226cbd7f8b76544b0

#2 lore raw

Hi Junio,

Quoted 23 lines · Junio C Hamano

"Johannes Schindelin via GitGitGadget" <[email protected]>

Quoted 20 lines · writes:

From: Johannes Schindelin <[email protected]>

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.

---
Fix Azure Pipelines for t0000

Quoted 8 lines
Quoted 3 lines

When running t0000 in our Azure Pipeline, the "Publish Test Results" step complains about an invalid JUnit-style XML, and it is correct. Let's fix that.

Hmph, I have a vague recollection that I've seen this one, looked at the patch and even understood the issue. Did I then forget to apply it back then? If so, apologies for failing to do so before the release.

I suspect that you think of 076ee3e8a2a6 (tests: fix --write-junit-xml with subshells, 2020-02-12) which you indeed applied. This patch addresses a different issue that I had not noticed until two weeks ago. I purposefully held back on contributing it during the feature freeze phase.

Quoted 1 line

Will queue.

Thanks,
Dscho

Quoted 26 lines

Thanks.

Quoted 21 lines

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-732%2Fdscho%2Fci-xml-error-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-732/dscho/ci-xml-error-v1
Pull-Request: https://github.com/git/git/pull/732

 t/test-lib.sh | 1 +
 1 file changed, 1 insertion(+)
t/test-lib.sh +1 -0
index 0ea1e5a05ed..7f0c02c016b 100644
@@ -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"
 

base-commit: be8661a3286c67a5d4088f4226cbd7f8b76544b0