diff options
author | EuAndreh <eu@euandre.org> | 2021-06-26 13:17:29 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2021-06-26 13:17:29 -0300 |
commit | 9069f9eb2396a56e2d1b7300dc20940281420c0a (patch) | |
tree | e6340aee81dd2f55e4f9599b73bcfe7489e0d54e /aux/tests-lib.sh | |
parent | mv src/git-permalink.sh.in src/git-permalin.in (diff) | |
download | git-permalink-9069f9eb2396a56e2d1b7300dc20940281420c0a.tar.gz git-permalink-9069f9eb2396a56e2d1b7300dc20940281420c0a.tar.xz |
tests/*.sh: Print line number, STDOUT and STDERR when test fails
Diffstat (limited to 'aux/tests-lib.sh')
-rwxr-xr-x | aux/tests-lib.sh | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/aux/tests-lib.sh b/aux/tests-lib.sh index 007282a..a3ce7dc 100755 --- a/aux/tests-lib.sh +++ b/aux/tests-lib.sh @@ -5,6 +5,7 @@ red="\033[0;31m" green="\033[0;32m" yellow="\033[0;33m" +N= OUT= ERR= STATUS= @@ -14,10 +15,15 @@ ERROR() { printf "${red}ERROR${end}" } +print_debug_info() { + printf 'LINENO: %s\nOUT: %s\nERR: %s\n' "$N" "$OUT" "$ERR" >&2 +} + assert_status() { if [ "$STATUS" != "$1" ]; then printf '\n%s: Bad status.\n\nexpected: %s\ngot: %s\n' \ "$(ERROR)" "$1" "$STATUS" >&2 + print_debug_info exit 1 fi } @@ -26,6 +32,7 @@ assert_usage() { if ! grep -Fq 'Usage' "$1"; then echo 'Expected to find "Usage" text, it was missing:' >&2 cat "$1" >&2 + print_debug_info exit 1 fi } @@ -34,6 +41,7 @@ assert_empty_stream() { if [ -s "$2" ]; then printf '\n%s: Expected %s (%s) to be empty, but has content:\n%s\n' \ "$(ERROR)" "$1" "$2" "$(cat "$2")" >&2 + print_debug_info exit 1 fi } @@ -50,6 +58,7 @@ assert_stream() { if [ "$(cat "$2")" != "$3" ]; then printf '\nERR: Bad %s (%s)\n\nexpected: %s\ngot: %s\n' \ "$1" "$2" "$3" "$(cat "$2")" >&2 + print_debug_info exit 1 fi } @@ -66,6 +75,7 @@ assert_grep_stream() { if ! grep -qE "$3" "$2"; then printf '\nERR: Bad %s (%s)\n\ngrepping: %s\nin:\n%s\n' \ "$1" "$2" "$3" "$(cat "$2")" >&2 + print_debug_info exit 1 fi } @@ -82,6 +92,7 @@ assert_fgrep_stream() { if ! grep -Fq -- "$3" "$2"; then printf '\nERR: Bad %s (%s)\n\ngrepping: %s\nin:\n%s\n' \ "$1" "$2" "$3" "$(cat "$2")" >&2 + print_debug_info exit 1 fi } |