From 61dab8bd75d36eb1b916e5c3dfc393c33a011027 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Fri, 11 Nov 2022 15:52:37 +0100 Subject: [PATCH] test: add support for new helper functions, skip/fail/check_dep Also, make sure to exit each test with the correct exit status. Signed-off-by: Joachim Wiberg --- test/tenv/lib.sh | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/test/tenv/lib.sh b/test/tenv/lib.sh index 8b431267..63cbb588 100755 --- a/test/tenv/lib.sh +++ b/test/tenv/lib.sh @@ -106,6 +106,31 @@ log() printf "\e[2m[%s]\e[0m %b%b%b %s\n" "$test" "$1" "$2" "$color_reset" "$3" } +say() +{ + log "$fg_yellow" • "$@" +} + +skip() +{ + log "$fg_yellow" − "$*" + exit 77 +} + +fail() +{ + log "$fg_red" ✘ "$*" + exit 99 +} + +# shellcheck disable=SC2068 +check_dep() +{ + if ! command -v "$1"; then + skip "Cannot find $1, skipping test." + fi +} + assert() { __assert_msg=$1 @@ -153,11 +178,6 @@ retry() return "$__retry_cmd_exit" } -say() -{ - log "$fg_yellow" • "$@" -} - teardown() { test_status="$?" @@ -169,6 +189,8 @@ teardown() log "$color_reset" '--' '' if [ "$test_status" -eq 0 ]; then log "$fg_green" 'TEST PASS' '' + elif [ "$test_status" -eq 77 ]; then + log "$fg_yellow" 'TEST SKIP' '' else log "$fg_red" 'TEST FAIL' '' fi @@ -179,6 +201,7 @@ teardown() wait rm -f "$TENV_ROOT"/running_test.pid + exit $test_status } trap teardown EXIT