Skip to content

Commit 076ee3e

Browse files
dschogitster
authored andcommitted
tests: fix --write-junit-xml with subshells
In t0000, more precisely in its `test_bool_env` test case, there are two subshells that are supposed to fail. To be even _more_ precise, they fail by calling the `error` function, and that is okay, because it is in a subshell, and it is expected that those two subshell invocations fail. However, the `error` function also tries to finalize the JUnit XML (if that XML was asked for, via `--write-junit-xml`. As a consequence, the XML is edited to add a `time` attribute for the `testsuite` tag. And since there are two expected `error` calls in addition to the final `test_done`, the `finalize_junit_xml` function is called three times and naturally the `time` attribute is added _three times_. Azure Pipelines is not happy with that, complaining thusly: ##[warning]Failed to read D:\a\1\s\t\out\TEST-t0000-basic.xml. Error : 'time' is a duplicate attribute name. Line 2, position 82.. One possible way to address this would be to unset `write_junit_xml` in the `test_bool_env` test case. But that would be fragile, as other `error` calls in subshells could be introduced. So let's just modify `finalize_junit_xml` to remove any `time` attribute before adding the authoritative one. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b6d4d82 commit 076ee3e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

t/test-lib.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,8 @@ finalize_junit_xml () {
10791079

10801080
# adjust the overall time
10811081
junit_time=$(test-tool date getnanos $junit_suite_start)
1082-
sed "s/<testsuite [^>]*/& time=\"$junit_time\"/" \
1082+
sed -e "s/\(<testsuite.*\) time=\"[^\"]*\"/\1/" \
1083+
-e "s/<testsuite [^>]*/& time=\"$junit_time\"/" \
10831084
<"$junit_xml_path" >"$junit_xml_path.new"
10841085
mv "$junit_xml_path.new" "$junit_xml_path"
10851086

0 commit comments

Comments
 (0)