Re: [PATCH v3 15/21] tests: include detailed trace logs with --write-junit-xml upon failure
From: Johannes Schindelin <hidden>
Date: 2019-01-17 10:18:39
Hi, On Wed, 16 Jan 2019, Johannes Schindelin via GitGitGadget wrote:
quoted hunk ↗ jump to hunk
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"
Ooops. This does not work. The intention of this patch was to remember the file size of the tee output file at the point when the previous test case was done, and skip that part (so that the first thing the user sees is the detailed trace of *just* the failed test case, with the complete trace being attached as `Standard_Error_Output.log`). However, I totally misunderstood that `cut` is *always* line based. So this `cut -c` (which should have been a `cut -b` to begin with) is just plain wrong. And since there is no easy Unix shell tool to just skip a bunch of bytes (`dd` comes close, but you have to abuse the buffer size to specify the number of bytes, or use buffer size 1, neither of which I like), I will just add a dozen lines to the `test-path-utils.c` to get problem fixed.
quoted hunk ↗ jump to hunk
+ 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
Also, in case anybody wonders, this `GIT_TEST_TEE_ERR_OFFSET` variable is no longer used, and I should have removed it. Oh well, I will just queue up the fixes in preparation for v4. Ciao, Dscho
+ fi fi # Provide an implementation of the 'yes' utility -- gitgitgadget