@@ -30,6 +30,11 @@ PATH="$ROOTDIR/test/bin:$ROOTDIR/bin:$ROOTDIR/share/github-backup-utils:$PATH"
3030TMPDIR=" $ROOTDIR /test/tmp"
3131TRASHDIR=" $TMPDIR /$( basename " $0 " ) -$$ "
3232
33+ test_suite_file_name=" $( basename " ${BASH_SOURCE[1]} " ) "
34+ test_suite_name=" ${GHE_TEST_SUITE_NAME:- ${test_suite_file_name% .* } } "
35+ results_file=" $TMPDIR /results"
36+ test_suite_before_time=$( date ' +%s.%3N' )
37+
3338# Set GIT_{AUTHOR,COMMITTER}_{NAME,EMAIL}
3439# This removes the assumption that a git config that specifies these is present.
3540export GIT_AUTHOR_NAME=make GIT_AUTHOR_EMAIL=make GIT_COMMITTER_NAME=make GIT_COMMITTER_EMAIL=make
@@ -57,14 +62,52 @@ ghe_remote_version_config "$GHE_TEST_REMOTE_VERSION"
5762# ghe-restore process groups
5863unset GHE_SNAPSHOT_TIMESTAMP
5964
65+ # Color definitions for log output
66+ color_reset=$( printf ' \e[0m' )
67+ # Display commands (lines starting with + in the output) in purple
68+ color_command=$( printf ' \e[0;35m' )
69+ # Display exit code line in red
70+ color_error_message=$( printf ' \e[0;31m' )
71+ # Display test suite name in blue
72+ color_test_suite=$( printf ' \e[0;34m' )
73+ # Display successful tests in bold green
74+ color_pass=$( printf ' \e[1;32m' )
75+ # Display skipped tests in bold gray
76+ color_skip=$( printf ' \e[1;37m' )
77+ # Display failed tests in bold red
78+ color_fail=$( printf ' \e[1;31m' )
79+
6080# keep track of num tests and failures
6181tests=0
82+ successes=0
83+ skipped=0
6284failures=0
6385
6486# this runs at process exit
6587atexit () {
6688 res=$?
6789
90+ test_suite_after_time=$( date ' +%s.%3N' )
91+ test_suite_elapsed_time=$( echo " scale=3; $test_suite_after_time - $test_suite_before_time " | bc)
92+
93+ # Temporarily redirect stdout output to results file
94+ exec 3< & 1
95+ exec 1>> " $results_file "
96+
97+ # Print test summary for this test suite
98+ echo -n " | $test_suite_name | "
99+
100+ if [ " $failures " -eq " 0" ]; then
101+ echo -n " :green_circle: passed"
102+ else
103+ echo -n " :red_circle: failed"
104+ fi
105+
106+ printf " | $successes | $failures | $skipped | %.3f s |\\ n" " $test_suite_elapsed_time "
107+
108+ # Restore stdout
109+ exec 1< & 3
110+
68111 [ -z " $KEEPTRASH " ] && rm -rf " $TRASHDIR "
69112 if [ $failures -gt 0 ]; then
70113 exit 1
@@ -145,36 +188,53 @@ begin_test () {
145188
146189 # allow the subshell to exit non-zero without exiting this process
147190 set -x +e
148- before_time=$( date ' +%s' )
191+ before_time=$( date ' +%s.%3N' )
192+
193+ # Marker to truncate the actual test output later
194+ echo " begin_test_truncate_marker" > /dev/null
149195}
150196
151- report_failure () {
152- msg= $1
153- desc= $2
154- failures= $(( failures + 1 ))
155- printf " test: %-73s $msg \\ n " " $desc ... "
156- (
157- sed ' s/^/ / ' < " $TRASHDIR /out " |
158- grep -a -v -e ' ^\+ end_test ' -e ' ^+ set +x ' - " $TRASHDIR /out " |
159- sed ' s/[+] test_status=/test failed. last command exited with / ' |
160- sed ' s/^/ / '
161- ) 1>&2
197+ report_failure_output () {
198+ echo " ::group::Output of failed test " 1>&2
199+ # Truncate the test output to exclude testing-related instructions
200+ echo " $( < " $TRASHDIR /out " ) " \
201+ | sed ' 0,/begin_test_truncate_marker/d ' \
202+ | sed -n ' /end_test_truncate_marker/q;p ' | head -n -2 \
203+ | sed " s/^\(+.*\)$/ ${color_command} \1 ${color_reset} / " \
204+ 1>&2
205+ echo -e " \n ${color_error_message} Test failed. The last command exited with exit code " \
206+ " $test_status . ${color_reset} " 1>&2
207+ echo " ::endgroup:: " 1>&2
162208}
163209
164210# Mark the end of a test.
165211end_test () {
166212 test_status=" ${1:- $? } "
167- after_time=$( date ' +%s' )
168- elapsed_time=$(( after_time - before_time))
213+
214+ # Marker to truncate the actual test output later
215+ echo " end_test_truncate_marker" > /dev/null
216+
217+ after_time=$( date ' +%s.%3N' )
218+ elapsed_time=$( echo " scale=3; $after_time - $before_time " | bc)
169219 set +x -e
170220 exec 1>&3 2>&4
171221
172222 if [ " $test_status " -eq 0 ]; then
173- printf " test: %-65s OK (${elapsed_time} s)\\ n" " $test_description ..."
223+ successes=$(( successes + 1 ))
224+ printf " ${color_pass} PASS${color_reset} " 1>&2
174225 elif [ " $test_status " -eq 254 ]; then
175- printf " test: %-65s SKIPPED\\ n" " $test_description ..."
226+ skipped=$(( skipped + 1 ))
227+ printf " ${color_skip} SKIP${color_reset} " 1>&2
176228 else
177- report_failure " FAILED (${elapsed_time} s)" " $test_description ..."
229+ failures=$(( failures + 1 ))
230+ printf " ${color_fail} FAIL${color_reset} " 1>&2
231+ fi
232+
233+ printf " [%8.3f s] ${color_test_suite} $test_suite_name ${color_reset} $test_description \\ n" \
234+ " $elapsed_time " 1>&2
235+
236+ if [ " $test_status " -ne 0 ] && [ " $test_status " -ne 254 ]; then
237+ report_failure_output
178238 fi
179239
180240 unset test_description
@@ -408,7 +468,6 @@ setup_minio_test_data() {
408468 bucket=" packages"
409469
410470 mkdir -p " $bucket "
411- echo " an example blob" " $bucket /91dfa09f-1801-4e00-95ee-6b763d7da3e2"
412471}
413472
414473cleanup_minio_test_data () {
0 commit comments