2019-09-20 21:44:51 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2019-09-26 21:53:50 +00:00
|
|
|
export NAVI_FORCE_GNU=true
|
|
|
|
|
2019-10-11 17:33:16 +00:00
|
|
|
source "${NAVI_HOME}/src/main.sh"
|
|
|
|
source "${NAVI_HOME}/test/log.sh"
|
2019-09-20 21:44:51 +00:00
|
|
|
|
2019-09-24 19:13:57 +00:00
|
|
|
opts::eval "$@"
|
2019-10-11 17:33:16 +00:00
|
|
|
TEST_DIR="${NAVI_HOME}/test"
|
2019-09-23 20:46:16 +00:00
|
|
|
|
2019-09-23 11:56:15 +00:00
|
|
|
PASSED=0
|
|
|
|
FAILED=0
|
2019-09-26 21:53:50 +00:00
|
|
|
SKIPPED=0
|
2019-09-26 15:15:11 +00:00
|
|
|
SUITE=""
|
2019-09-23 11:56:15 +00:00
|
|
|
|
2019-09-26 21:53:50 +00:00
|
|
|
test::set_suite() {
|
|
|
|
SUITE="$*"
|
|
|
|
}
|
|
|
|
|
2019-09-20 21:44:51 +00:00
|
|
|
test::success() {
|
2019-09-23 11:56:15 +00:00
|
|
|
PASSED=$((PASSED+1))
|
2019-09-24 19:13:57 +00:00
|
|
|
log::success "Test passed!"
|
2019-09-20 21:44:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test::fail() {
|
2019-09-23 11:56:15 +00:00
|
|
|
FAILED=$((FAILED+1))
|
2019-09-24 19:13:57 +00:00
|
|
|
log::error "Test failed..."
|
2019-09-23 11:56:15 +00:00
|
|
|
return
|
2019-09-21 22:21:46 +00:00
|
|
|
}
|
|
|
|
|
2019-09-26 21:53:50 +00:00
|
|
|
test::skip() {
|
|
|
|
echo
|
|
|
|
log::note "${SUITE:-unknown} - ${1:-unknown}"
|
|
|
|
SKIPPED=$((SKIPPED+1))
|
|
|
|
log::warning "Test skipped..."
|
|
|
|
return
|
2019-09-26 15:15:11 +00:00
|
|
|
}
|
|
|
|
|
2019-09-21 22:21:46 +00:00
|
|
|
test::run() {
|
2019-09-21 22:24:09 +00:00
|
|
|
echo
|
2019-09-26 15:15:11 +00:00
|
|
|
log::note "${SUITE:-unknown} - ${1:-unknown}"
|
2019-09-21 22:24:09 +00:00
|
|
|
shift
|
|
|
|
eval "$*" && test::success || test::fail
|
2019-09-23 11:56:15 +00:00
|
|
|
}
|
|
|
|
|
2019-09-23 20:46:16 +00:00
|
|
|
test::equals() {
|
2019-09-25 14:44:57 +00:00
|
|
|
local -r actual="$(cat)"
|
|
|
|
local -r expected="$(echo "${1:-}")"
|
2019-09-23 20:46:16 +00:00
|
|
|
|
|
|
|
if [[ "$actual" != "$expected" ]]; then
|
2019-09-25 14:44:57 +00:00
|
|
|
log::error "Expected '${expected}' but got '${actual}'"
|
2019-09-23 20:46:16 +00:00
|
|
|
return 2
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-09-23 11:56:15 +00:00
|
|
|
test::finish() {
|
|
|
|
echo
|
2019-09-26 21:53:50 +00:00
|
|
|
if [ $SKIPPED -gt 0 ]; then
|
|
|
|
log::warning "${SKIPPED} tests skipped!"
|
|
|
|
fi
|
2019-09-23 11:56:15 +00:00
|
|
|
if [ $FAILED -gt 0 ]; then
|
2019-09-24 19:13:57 +00:00
|
|
|
log::error "${PASSED} tests passed but ${FAILED} failed... :("
|
2019-09-23 11:56:15 +00:00
|
|
|
exit "${FAILED}"
|
|
|
|
else
|
2019-09-24 19:13:57 +00:00
|
|
|
log::success "All ${PASSED} tests passed! :)"
|
2019-09-23 11:56:15 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
}
|