Skip to content

Commit 0aca55d

Browse files
committed
fixup! tests: include detailed trace logs with --write-junit-xml upon failure
It is actually better not to modify (or even truncate) the .out files because the ci/ scripts want to provide a full output in the log. So let's just remember the file offset at the beginning of each test case, and use `cut <offset>-` to use that specifically. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 2d28b0f commit 0aca55d

File tree

1 file changed

+20
-32
lines changed

1 file changed

+20
-32
lines changed

t/test-lib.sh

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -513,35 +513,21 @@ test_ok_ () {
513513
test_failure_ () {
514514
if test -n "$write_junit_xml"
515515
then
516-
if test -z "$GIT_TEST_TEE_OUTPUT_FILE"
517-
then
518-
# clean up
519-
test_atexit_handler
520-
521-
# re-run with --verbose-log
522-
echo "# Re-running: $junit_rerun_options_sq" >&2
523-
524-
cd "$TEST_DIRECTORY" &&
525-
eval "${TEST_SHELL_PATH}" "$junit_rerun_options_sq" \
526-
>/dev/null 2>&1
527-
status=$?
528-
529-
say_color "" "$(test 0 = $status ||
530-
echo "not ")ok $test_count - (re-ran with trace)"
531-
say "1..$test_count"
532-
GIT_EXIT_OK=t
533-
exit $status
534-
fi
535-
536516
junit_insert="<failure message=\"not ok $test_count -"
537517
junit_insert="$junit_insert $(xml_attr_encode "$1")\">"
538518
junit_insert="$junit_insert $(xml_attr_encode \
539-
"$(cat "$GIT_TEST_TEE_OUTPUT_FILE")")"
540-
>"$GIT_TEST_TEE_OUTPUT_FILE"
519+
"$(if test -n "$GIT_TEST_TEE_OUTPUT_FILE"
520+
then
521+
cut -c "$GIT_TEST_TEE_OFFSET-" <"$GIT_TEST_TEE_OUTPUT_FILE"
522+
else
523+
printf '%s\n' "$@" | sed 1d
524+
fi)")"
541525
junit_insert="$junit_insert</failure>"
542-
junit_insert="$junit_insert<system-err>$(xml_attr_encode \
543-
"$(cat "$GIT_TEST_TEE_OUTPUT_FILE.err")")</system-err>"
544-
>"$GIT_TEST_TEE_OUTPUT_FILE.err"
526+
if test -n "$GIT_TEST_TEE_OUTPUT_FILE"
527+
then
528+
junit_insert="$junit_insert<system-err>$(xml_attr_encode \
529+
"$(cat "$GIT_TEST_TEE_OUTPUT_FILE")")</system-err>"
530+
fi
545531
write_junit_xml_testcase "$1" " $junit_insert"
546532
fi
547533
test_failure=$(($test_failure + 1))
@@ -830,13 +816,6 @@ test_start_ () {
830816
if test -n "$write_junit_xml"
831817
then
832818
junit_start=$(test-tool date getnanos)
833-
834-
# append to future <system-err>; truncate output
835-
test -z "$GIT_TEST_TEE_OUTPUT_FILE" || {
836-
cat "$GIT_TEST_TEE_OUTPUT_FILE" \
837-
>>"$GIT_TEST_TEE_OUTPUT_FILE.err"
838-
>"$GIT_TEST_TEE_OUTPUT_FILE"
839-
}
840819
fi
841820
}
842821

@@ -928,6 +907,10 @@ write_junit_xml_testcase () {
928907
write_junit_xml "$(printf '%s\n' \
929908
" <testcase $junit_attrs>" "$@" " </testcase>")"
930909
junit_have_testcase=t
910+
if test -n "$GIT_TEST_TEE_OUTPUT_FILE"
911+
then
912+
GIT_TEST_TEE_OFFSET=$(perl -e 'print -s $ARGV[0]' "$GIT_TEST_TEE_OUTPUT_FILE")
913+
fi
931914
}
932915

933916
test_done () {
@@ -1218,6 +1201,11 @@ then
12181201
date +%Y-%m-%dT%H:%M:%S)\""
12191202
write_junit_xml --truncate "<testsuites>" " <testsuite $junit_attrs>"
12201203
junit_suite_start=$(test-tool date getnanos)
1204+
if test -n "$GIT_TEST_TEE_OUTPUT_FILE"
1205+
then
1206+
GIT_TEST_TEE_OFFSET=0
1207+
GIT_TEST_TEE_ERR_OFFSET=0
1208+
fi
12211209
fi
12221210

12231211
# Provide an implementation of the 'yes' utility

0 commit comments

Comments
 (0)