Skip to content

Commit 400e48e

Browse files
committed
Report test runtime in milliseconds
1 parent e029f68 commit 400e48e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

test/testlib.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ begin_test () {
143143

144144
# allow the subshell to exit non-zero without exiting this process
145145
set -x +e
146-
before_time=$(date '+%s')
146+
before_time=$(date '+%s.%3N')
147147
}
148148

149149
report_failure_output () {
@@ -158,18 +158,18 @@ report_failure_output () {
158158
# Mark the end of a test.
159159
end_test () {
160160
test_status="${1:-$?}"
161-
after_time=$(date '+%s')
162-
elapsed_time=$((after_time - before_time))
161+
after_time=$(date '+%s.%3N')
162+
elapsed_time=$(echo "scale=3; $after_time - $before_time" | bc)
163163
set +x -e
164164
exec 1>&3 2>&4
165165

166166
if [ "$test_status" -eq 0 ]; then
167-
printf "test: %-65s OK (${elapsed_time}s)\\n" "$test_description ..."
167+
printf "test: %-65s OK (%.3fs)\\n" "$test_description ..." "$elapsed_time"
168168
elif [ "$test_status" -eq 254 ]; then
169169
printf "test: %-65s SKIPPED\\n" "$test_description ..."
170170
else
171171
failures=$(( failures + 1 ))
172-
printf "test: %-65s FAILED (${elapsed_time}s)\\n" "$test_description ..."
172+
printf "test: %-65s FAILED (%.3fs)\\n" "$test_description ..." "$elapsed_time"
173173
report_failure_output
174174
fi
175175

0 commit comments

Comments
 (0)