mirror of
https://github.com/ovh/debian-cis.git
synced 2024-11-26 07:21:22 +01:00
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)
This commit is contained in:
parent
e8ae07c2e8
commit
a1a4295dcf
@ -12,6 +12,9 @@ totalerrors=255
|
|||||||
|
|
||||||
cleanup_and_exit() {
|
cleanup_and_exit() {
|
||||||
rm -rf "$mytmpdir"
|
rm -rf "$mytmpdir"
|
||||||
|
if [ "$totalerrors" -eq 255 ]; then
|
||||||
|
fatal "RUNTIME ERROR"
|
||||||
|
fi
|
||||||
exit $totalerrors
|
exit $totalerrors
|
||||||
}
|
}
|
||||||
trap "cleanup_and_exit" EXIT HUP INT
|
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
|
# in case a fatal event occurs, fatal logs and exits with return code 1
|
||||||
fatal() {
|
fatal() {
|
||||||
|
printf "\033[1;91m###### \033[0m\n" >&2
|
||||||
printf "%b %b\n" "\033[1;91mFATAL\033[0m" "$*" >&2
|
printf "%b %b\n" "\033[1;91mFATAL\033[0m" "$*" >&2
|
||||||
printf "%b \n" "\033[1;91mEXIT TEST SUITE WITH FAILURE\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
|
# prints that a test failed
|
||||||
fail() {
|
fail() {
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
# describe <STRING>
|
# describe <STRING>
|
||||||
describe() {
|
describe() {
|
||||||
# shellcheck disable=2154
|
# 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
|
# Register an assertion on an audit before running it
|
||||||
|
Loading…
Reference in New Issue
Block a user