Skip to content

Commit 4d458bc

Browse files
committed
Reformat and colorize test logs for legibility
This reformats the test logs to improve legibility. A key change is highlighting the test result with corresponding colors to make it easier for developers to spot tests that have failed at a quick glance. The test result and duration are moved to the front of each line to avoid formatting issues because of very long test descriptions that are hard to format in a layout with fixed column widths. Also, this colorizes the commands captured by set -x to visually distinguish them from the actual command output.
1 parent b8d781f commit 4d458bc

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

test/testlib.sh

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,23 @@ ghe_remote_version_config "$GHE_TEST_REMOTE_VERSION"
5757
# ghe-restore process groups
5858
unset GHE_SNAPSHOT_TIMESTAMP
5959

60+
# Color definitions for log output
61+
color_reset=$(printf '\e[0m')
62+
# Display commands (lines starting with + in the output) in purple
63+
color_command=$(printf '\e[0;35m')
64+
# Display exit code line in red
65+
color_error_message=$(printf '\e[0;31m')
66+
# Display successful tests in bold green
67+
color_pass=$(printf '\e[1;32m')
68+
# Display skipped tests in bold gray
69+
color_skip=$(printf '\e[1;37m')
70+
# Display failed tests in bold red
71+
color_fail=$(printf '\e[1;31m')
72+
6073
# keep track of num tests and failures
6174
tests=0
75+
successes=0
76+
skipped=0
6277
failures=0
6378

6479
# this runs at process exit
@@ -155,8 +170,10 @@ report_failure_output () {
155170
echo "$(<"$TRASHDIR/out")" \
156171
| sed '0,/begin_test_truncate_marker/d' \
157172
| sed -n '/end_test_truncate_marker/q;p' | head -n -2 \
173+
| sed "s/^\(+.*\)$/${color_command}\1${color_reset}/" \
158174
1>&2
159-
echo -e "\nTest failed. The last command exited with exit code $test_status." 1>&2
175+
echo -e "\n${color_error_message}Test failed. The last command exited with exit code" \
176+
"$test_status.${color_reset}" 1>&2
160177
echo "::endgroup::" 1>&2
161178
}
162179

@@ -173,12 +190,19 @@ end_test () {
173190
exec 1>&3 2>&4
174191

175192
if [ "$test_status" -eq 0 ]; then
176-
printf "test: %-65s OK (%.3fs)\\n" "$test_description ..." "$elapsed_time"
193+
successes=$(( successes + 1 ))
194+
printf "${color_pass}PASS${color_reset}" 1>&2
177195
elif [ "$test_status" -eq 254 ]; then
178-
printf "test: %-65s SKIPPED\\n" "$test_description ..."
196+
skipped=$(( skipped + 1 ))
197+
printf "${color_skip}SKIP${color_reset}" 1>&2
179198
else
180199
failures=$(( failures + 1 ))
181-
printf "test: %-65s FAILED (%.3fs)\\n" "$test_description ..." "$elapsed_time"
200+
printf "${color_fail}FAIL${color_reset}" 1>&2
201+
fi
202+
203+
printf " [%8.3f s] $test_description\\n" "$elapsed_time" 1>&2
204+
205+
if [ "$test_status" -ne 0 ] && [ "$test_status" -ne 254 ]; then
182206
report_failure_output
183207
fi
184208

0 commit comments

Comments
 (0)