2020-03-19 12:19:50 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# vim: filetype=sh
|
|
|
|
|
|
|
|
source "${NAVI_HOME}/scripts/install"
|
|
|
|
|
2021-08-07 15:24:39 +00:00
|
|
|
NEWLINE_CHAR="\036"
|
|
|
|
|
2020-03-19 12:19:50 +00:00
|
|
|
PASSED=0
|
|
|
|
FAILED=0
|
|
|
|
SKIPPED=0
|
|
|
|
SUITE=""
|
|
|
|
|
|
|
|
test::set_suite() {
|
|
|
|
SUITE="$*"
|
|
|
|
}
|
|
|
|
|
|
|
|
test::success() {
|
|
|
|
PASSED=$((PASSED+1))
|
|
|
|
log::success "Test passed!"
|
|
|
|
}
|
|
|
|
|
|
|
|
test::fail() {
|
|
|
|
FAILED=$((FAILED+1))
|
|
|
|
log::error "Test failed..."
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
test::skip() {
|
|
|
|
echo
|
|
|
|
log::note "${SUITE:-unknown} - ${1:-unknown}"
|
|
|
|
SKIPPED=$((SKIPPED+1))
|
|
|
|
log::warning "Test skipped..."
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
test::run() {
|
|
|
|
echo
|
|
|
|
log::note "${SUITE:-unknown} - ${1:-unknown}"
|
|
|
|
shift
|
|
|
|
"$@" && test::success || test::fail
|
|
|
|
}
|
|
|
|
|
2021-08-07 15:24:39 +00:00
|
|
|
test::_escape() {
|
2021-08-07 18:57:22 +00:00
|
|
|
tr '\n' "$NEWLINE_CHAR" | sed -E "s/[\s$(printf "$NEWLINE_CHAR") ]+$//g"
|
2021-08-07 15:24:39 +00:00
|
|
|
}
|
|
|
|
|
2020-03-19 12:19:50 +00:00
|
|
|
test::equals() {
|
|
|
|
local -r actual="$(cat)"
|
|
|
|
local -r expected="$(echo "${1:-}")"
|
2021-08-08 11:12:19 +00:00
|
|
|
|
2021-08-07 15:24:39 +00:00
|
|
|
local -r actual2="$(echo "$actual" | test::_escape)"
|
|
|
|
local -r expected2="$(echo "$expected" | test::_escape)"
|
2020-03-19 12:19:50 +00:00
|
|
|
|
|
|
|
if [[ "$actual2" != "$expected2" ]]; then
|
|
|
|
log::error "Expected '${expected}' but got '${actual}'"
|
|
|
|
return 2
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
test::finish() {
|
|
|
|
echo
|
|
|
|
if [ $SKIPPED -gt 0 ]; then
|
|
|
|
log::warning "${SKIPPED} tests skipped!"
|
|
|
|
fi
|
|
|
|
if [ $FAILED -gt 0 ]; then
|
|
|
|
log::error "${PASSED} tests passed but ${FAILED} failed... :("
|
|
|
|
exit "${FAILED}"
|
|
|
|
else
|
|
|
|
log::success "All ${PASSED} tests passed! :)"
|
|
|
|
exit 0
|
|
|
|
fi
|
2020-09-11 14:59:34 +00:00
|
|
|
}
|