From a1a4295dcf070dca90d17bd7e9333d6b8812a40f Mon Sep 17 00:00:00 2001 From: Charles Herlin Date: Thu, 24 Jan 2019 15:53:09 +0100 Subject: [PATCH] IMP: tests readability and runtime error handling Change describe display to add underline in order to make it more noticeable in a stream of logs Add a `fatal` message when catching a runtime error (until `$totalerrors` has not been modified yet) --- tests/launch_tests.sh | 7 ++++++- tests/lib.sh | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/launch_tests.sh b/tests/launch_tests.sh index fa7a839..256efad 100755 --- a/tests/launch_tests.sh +++ b/tests/launch_tests.sh @@ -12,6 +12,9 @@ totalerrors=255 cleanup_and_exit() { rm -rf "$mytmpdir" + if [ "$totalerrors" -eq 255 ]; then + fatal "RUNTIME ERROR" + fi exit $totalerrors } trap "cleanup_and_exit" EXIT HUP INT @@ -42,9 +45,11 @@ declare -a REGISTERED_TESTS ##################### # in case a fatal event occurs, fatal logs and exits with return code 1 fatal() { + printf "\033[1;91m###### \033[0m\n" >&2 printf "%b %b\n" "\033[1;91mFATAL\033[0m" "$*" >&2 printf "%b \n" "\033[1;91mEXIT TEST SUITE WITH FAILURE\033[0m" >&2 - exit 1 + trap - EXIT + exit 255 } # prints that a test failed fail() { diff --git a/tests/lib.sh b/tests/lib.sh index 374ce81..32b9e42 100644 --- a/tests/lib.sh +++ b/tests/lib.sh @@ -8,7 +8,7 @@ # describe describe() { # shellcheck disable=2154 - printf "\033[36mxxx %s::%s \033[0m\n" "$name" "$*" + printf "\033[4;36mxxx %s::%s \033[0m\n" "$name" "$*" } # Register an assertion on an audit before running it