Skip to content

Commit cd3cbbb

Browse files
committed
Truncate test output to exclude test instructions
This adds markers right before starting a test case and right after it completed, which are then used to truncate the output of the test case so that it doesn’t include any instructions related to the testing framework, as these aren’t relevant to users inspecting the test ouptut.
1 parent 400e48e commit cd3cbbb

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

test/testlib.sh

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,20 +144,28 @@ begin_test () {
144144
# allow the subshell to exit non-zero without exiting this process
145145
set -x +e
146146
before_time=$(date '+%s.%3N')
147+
148+
# Marker to truncate the actual test output later
149+
echo "begin_test_truncate_marker" > /dev/null
147150
}
148151

149152
report_failure_output () {
150-
(
151-
sed 's/^/ /' <"$TRASHDIR/out" |
152-
grep -a -v -e '^\+ end_test' -e '^+ set +x' |
153-
sed 's/[+] test_status=/test failed. last command exited with /' |
154-
sed 's/^/ /'
155-
) 1>&2
153+
# Truncate the test output to exclude testing-related instructions
154+
echo "$(<"$TRASHDIR/out")" \
155+
| sed '0,/begin_test_truncate_marker/d' \
156+
| sed -n '/end_test_truncate_marker/q;p' | head -n -2 \
157+
| sed 's/^/ /' \
158+
1>&2
159+
echo -e "\nTest failed. The last command exited with exit code $test_status." 1>&2
156160
}
157161

158162
# Mark the end of a test.
159163
end_test () {
160164
test_status="${1:-$?}"
165+
166+
# Marker to truncate the actual test output later
167+
echo "end_test_truncate_marker" > /dev/null
168+
161169
after_time=$(date '+%s.%3N')
162170
elapsed_time=$(echo "scale=3; $after_time - $before_time" | bc)
163171
set +x -e

0 commit comments

Comments
 (0)