From: Johannes Schindelin <johannes.schindelin@xxxxxx> The JUnit XML format lends itself to be presented in a powerful UI, where you can drill down to the information you are interested in very quickly. For test failures, this usually means that you want to see the detailed trace of the failing tests. With Travis CI, we passed the `--verbose-log` option to get those traces. However, that seems excessive, as we do not need/use the logs in almost all of those cases: only when a test fails do we have a way to include the trace. So let's do something different when using Azure DevOps: let's run all the tests with `--quiet` first, and only if a failure is encountered, try to trace the commands as they are executed. Of course, we cannot turn on `--verbose-log` after the fact. So let's just re-run the test with all the same options, adding `--verbose-log`. And then munging the output file into the JUnit XML on the fly. Note: there is an off chance that re-running the test in verbose mode "fixes" the failures (and this does happen from time to time!). That is a possibility we should be able to live with. Ideally, we would label this as "Passed upon rerun", and Azure Pipelines even know about that outcome, but it is not available when using the JUnit XML format for now: https://github.com/Microsoft/azure-pipelines-agent/blob/master/src/Agent.Worker/TestResults/JunitResultReader.cs Signed-off-by: Johannes Schindelin <johannes.schindelin@xxxxxx> --- t/test-lib.sh | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/t/test-lib.sh b/t/test-lib.sh index e9782b6b32..f5371f505a 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -503,8 +503,18 @@ test_failure_ () { junit_insert="<failure message=\"not ok $test_count -" junit_insert="$junit_insert $(xml_attr_encode "$1")\">" junit_insert="$junit_insert $(xml_attr_encode \ - "$(printf '%s\n' "$@" | sed 1d)")" + "$(if test -n "$GIT_TEST_TEE_OUTPUT_FILE" + then + cut -c "$GIT_TEST_TEE_OFFSET-" <"$GIT_TEST_TEE_OUTPUT_FILE" + else + printf '%s\n' "$@" | sed 1d + fi)")" junit_insert="$junit_insert</failure>" + if test -n "$GIT_TEST_TEE_OUTPUT_FILE" + then + junit_insert="$junit_insert<system-err>$(xml_attr_encode \ + "$(cat "$GIT_TEST_TEE_OUTPUT_FILE")")</system-err>" + fi write_junit_xml_testcase "$1" " $junit_insert" fi test_failure=$(($test_failure + 1)) @@ -872,6 +882,11 @@ write_junit_xml_testcase () { write_junit_xml "$(printf '%s\n' \ " <testcase $junit_attrs>" "$@" " </testcase>")" junit_have_testcase=t + if test -n "$GIT_TEST_TEE_OUTPUT_FILE" + then + GIT_TEST_TEE_OFFSET=$(test-tool path-utils file-size \ + "$GIT_TEST_TEE_OUTPUT_FILE") + fi } test_done () { @@ -1153,6 +1168,11 @@ then date +%Y-%m-%dT%H:%M:%S)\"" write_junit_xml --truncate "<testsuites>" " <testsuite $junit_attrs>" junit_suite_start=$(test-tool date getnanos) + if test -n "$GIT_TEST_TEE_OUTPUT_FILE" + then + GIT_TEST_TEE_OFFSET=0 + GIT_TEST_TEE_ERR_OFFSET=0 + fi fi # Provide an implementation of the 'yes' utility -- gitgitgadget