Skip to content

Commit 0d60b87

Browse files
committed
tests: record more stderr with --write-junit-xml in case of failure
Sometimes, failures in a test case are actually caused by issues in earlier test cases. To make it easier to see those issues, let's attach the output from before the failing test case (i.e. stdout/stderr since the previous failing test case, or the start of the test script). This will be visible in the "Attachments" of the details of the failed test. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 1b82783 commit 0d60b87

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

t/test-lib.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,9 @@ test_failure_ () {
479479
"$(cat "$GIT_TEST_TEE_OUTPUT_FILE")")"
480480
>"$GIT_TEST_TEE_OUTPUT_FILE"
481481
junit_insert="$junit_insert</failure>"
482+
junit_insert="$junit_insert<system-err>$(xml_attr_encode \
483+
"$(cat "$GIT_TEST_TEE_OUTPUT_FILE.err")")</system-err>"
484+
>"$GIT_TEST_TEE_OUTPUT_FILE.err"
482485
write_junit_xml_testcase "$1" " $junit_insert"
483486
fi
484487
test_failure=$(($test_failure + 1))
@@ -763,9 +766,12 @@ test_start_ () {
763766
then
764767
junit_start=$(test-tool date getnanos)
765768

766-
# truncate output
767-
test -z "$GIT_TEST_TEE_OUTPUT_FILE" ||
768-
>"$GIT_TEST_TEE_OUTPUT_FILE"
769+
# append to future <system-err>; truncate output
770+
test -z "$GIT_TEST_TEE_OUTPUT_FILE" || {
771+
cat "$GIT_TEST_TEE_OUTPUT_FILE" \
772+
>>"$GIT_TEST_TEE_OUTPUT_FILE.err"
773+
>"$GIT_TEST_TEE_OUTPUT_FILE"
774+
}
769775
fi
770776
}
771777

0 commit comments

Comments
 (0)