Skip to content

Commit ab7d854

Browse files
dschogitster
authored andcommitted
tests: let --immediate and --write-junit-xml play well together
When the `--immediate` option is in effect, any test failure will immediately exit the test script. Together with `--write-junit-xml`, we will want the JUnit-style `.xml` file to be finalized (and not leave the XML incomplete). Let's make it so. This comes in particularly handy when trying to debug via Azure Pipelines, where the JUnit-style XML is consumed to present the test results in an informative and helpful way. While at it, also handle the `error()` code path. The only remaining code path that sets `GIT_EXIT_OK` happens whenever the trash directory could not be set up, i.e. long before the JUnit XML was written, therefore we should _not_ try to finalize that XML in that case. It is tempting to change the `immediate` code path to just hand off to `error`, simplifying the code in the process. That would, however, result in a change of behavior (an additional error message) in the test suite, which is outside of the purview of the current patch series: its goal is to allow building Git with Visual Studio and testing it with a portable version of Git for Windows. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent be5d88e commit ab7d854

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

t/test-lib.sh

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ export TERM
567567

568568
error () {
569569
say_color error "error: $*"
570+
finalize_junit_xml
570571
GIT_EXIT_OK=t
571572
exit 1
572573
}
@@ -695,7 +696,7 @@ test_failure_ () {
695696
say_color error "not ok $test_count - $1"
696697
shift
697698
printf '%s\n' "$*" | sed -e 's/^/# /'
698-
test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
699+
test "$immediate" = "" || { finalize_junit_xml; GIT_EXIT_OK=t; exit 1; }
699700
}
700701

701702
test_known_broken_ok_ () {
@@ -1063,6 +1064,25 @@ write_junit_xml_testcase () {
10631064
junit_have_testcase=t
10641065
}
10651066

1067+
finalize_junit_xml () {
1068+
if test -n "$write_junit_xml" && test -n "$junit_xml_path"
1069+
then
1070+
test -n "$junit_have_testcase" || {
1071+
junit_start=$(test-tool date getnanos)
1072+
write_junit_xml_testcase "all tests skipped"
1073+
}
1074+
1075+
# adjust the overall time
1076+
junit_time=$(test-tool date getnanos $junit_suite_start)
1077+
sed "s/<testsuite [^>]*/& time=\"$junit_time\"/" \
1078+
<"$junit_xml_path" >"$junit_xml_path.new"
1079+
mv "$junit_xml_path.new" "$junit_xml_path"
1080+
1081+
write_junit_xml " </testsuite>" "</testsuites>"
1082+
write_junit_xml=
1083+
fi
1084+
}
1085+
10661086
test_atexit_cleanup=:
10671087
test_atexit_handler () {
10681088
# In a succeeding test script 'test_atexit_handler' is invoked
@@ -1085,21 +1105,7 @@ test_done () {
10851105
# removed, so the commands can access pidfiles and socket files.
10861106
test_atexit_handler
10871107

1088-
if test -n "$write_junit_xml" && test -n "$junit_xml_path"
1089-
then
1090-
test -n "$junit_have_testcase" || {
1091-
junit_start=$(test-tool date getnanos)
1092-
write_junit_xml_testcase "all tests skipped"
1093-
}
1094-
1095-
# adjust the overall time
1096-
junit_time=$(test-tool date getnanos $junit_suite_start)
1097-
sed "s/<testsuite [^>]*/& time=\"$junit_time\"/" \
1098-
<"$junit_xml_path" >"$junit_xml_path.new"
1099-
mv "$junit_xml_path.new" "$junit_xml_path"
1100-
1101-
write_junit_xml " </testsuite>" "</testsuites>"
1102-
fi
1108+
finalize_junit_xml
11031109

11041110
if test -z "$HARNESS_ACTIVE"
11051111
then

0 commit comments

Comments
 (0)