diff options
author | EuAndreh <eu@euandre.org> | 2021-06-22 14:06:42 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2021-06-22 14:06:42 -0300 |
commit | c2ba87741bf563a348935563b0fbd68a3f0873f3 (patch) | |
tree | eb735476199dd281338087a4e463b0eb39768cae | |
parent | aux/workflow/TODOs.sh: Use <pre> over <span> for ids (diff) | |
download | remembering-c2ba87741bf563a348935563b0fbd68a3f0873f3.tar.gz remembering-c2ba87741bf563a348935563b0fbd68a3f0873f3.tar.xz |
aux/tests-lib.sh: Use colours in test reporting
-rwxr-xr-x | aux/tests-lib.sh | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/aux/tests-lib.sh b/aux/tests-lib.sh index e075974..0be4e6f 100755 --- a/aux/tests-lib.sh +++ b/aux/tests-lib.sh @@ -1,13 +1,23 @@ #!/bin/sh +end="\033[0m" +red="\033[0;31m" +green="\033[0;32m" +yellow="\033[0;33m" + OUT= ERR= STATUS= +ERROR() { + # shellcheck disable=2059 + printf "${red}ERROR${end}" +} + assert_status() { if [ "$STATUS" != "$1" ]; then - printf '\nERR: Bad status.\n\nexpected: %s\ngot: %s\n' \ - "$1" "$STATUS" >&2 + printf '\n%s: Bad status.\n\nexpected: %s\ngot: %s\n' \ + "$(ERROR)" "$1" "$STATUS" >&2 exit 1 fi } @@ -22,8 +32,8 @@ assert_usage() { assert_empty_stream() { if [ -s "$2" ]; then - printf '\nERR: Expected %s (%s) to be empty, but has content:\n%s\n' \ - "$1" "$2" "$(cat "$2")" >&2 + printf '\n%s: Expected %s (%s) to be empty, but has content:\n%s\n' \ + "$(ERROR)" "$1" "$2" "$(cat "$2")" >&2 exit 1 fi } @@ -85,9 +95,10 @@ assert_fgrep_stderr() { } testing() { - printf 'testing: %s...' "$1" >&2 + printf "${yellow}testing${end}: %s..." "$1" >&2 } test_ok() { - printf ' OK.\n' >&2 + # shellcheck disable=2059 + printf " ${green}OK${end}.\n" >&2 } |