mirror of
https://github.com/troglobit/finit.git
synced 2026-11-13 17:00:16 +00:00
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 <troglobit@gmail.com>
This commit is contained in:
1 parent
a7e81f45c6
commit
61dab8bd75
1 file changed
+28
-5
+28
-5
@@ -106,6 +106,31 @@ log()
|
|||||||
printf "\e[2m[%s]\e[0m %b%b%b %s\n" "$test" "$1" "$2" "$color_reset" "$3"
|
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()
|
||||||
{
|
{
|
||||||
__assert_msg=$1
|
__assert_msg=$1
|
||||||
@@ -153,11 +178,6 @@ retry()
|
|||||||
return "$__retry_cmd_exit"
|
return "$__retry_cmd_exit"
|
||||||
}
|
}
|
||||||
|
|
||||||
say()
|
|
||||||
{
|
|
||||||
log "$fg_yellow" • "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
teardown()
|
teardown()
|
||||||
{
|
{
|
||||||
test_status="$?"
|
test_status="$?"
|
||||||
@@ -169,6 +189,8 @@ teardown()
|
|||||||
log "$color_reset" '--' ''
|
log "$color_reset" '--' ''
|
||||||
if [ "$test_status" -eq 0 ]; then
|
if [ "$test_status" -eq 0 ]; then
|
||||||
log "$fg_green" 'TEST PASS' ''
|
log "$fg_green" 'TEST PASS' ''
|
||||||
|
elif [ "$test_status" -eq 77 ]; then
|
||||||
|
log "$fg_yellow" 'TEST SKIP' ''
|
||||||
else
|
else
|
||||||
log "$fg_red" 'TEST FAIL' ''
|
log "$fg_red" 'TEST FAIL' ''
|
||||||
fi
|
fi
|
||||||
@@ -179,6 +201,7 @@ teardown()
|
|||||||
wait
|
wait
|
||||||
|
|
||||||
rm -f "$TENV_ROOT"/running_test.pid
|
rm -f "$TENV_ROOT"/running_test.pid
|
||||||
|
exit $test_status
|
||||||
}
|
}
|
||||||
|
|
||||||
trap teardown EXIT
|
trap teardown EXIT
|
||||||
|
|||||||
Reference in new issue
Block a user