mirror of
https://github.com/denisidoro/navi
synced 2024-11-25 04:50:21 +00:00
Improve test runner (#41)
This commit is contained in:
parent
be92d158ad
commit
b3f8e0b374
9 changed files with 60 additions and 34 deletions
|
@ -40,9 +40,9 @@ opts::eval() {
|
|||
--command-for) wait_for="command-for" ;;
|
||||
--no-preview) preview=false ;;
|
||||
--path) wait_for="path" ;;
|
||||
search) entry_point="search"; wait_for="search";;
|
||||
preview) entry_point="preview"; wait_for="preview";;
|
||||
q|query) wait_for="query";;
|
||||
search) entry_point="search"; wait_for="search" ;;
|
||||
preview) entry_point="preview"; wait_for="preview" ;;
|
||||
q|query) wait_for="query" ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
|
4
test/cheat_test.sh
Normal file
4
test/cheat_test.sh
Normal file
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
test::run "We can find at least one known cheatsheet" \
|
||||
'cheat::find | grep -q "docker.cheat"'
|
18
test/core.sh
18
test/core.sh
|
@ -2,13 +2,18 @@
|
|||
|
||||
source "${SCRIPT_DIR}/src/main.sh"
|
||||
|
||||
PASSED=0
|
||||
FAILED=0
|
||||
|
||||
test::success() {
|
||||
PASSED=$((PASSED+1))
|
||||
echo "Test passed!"
|
||||
}
|
||||
|
||||
test::fail() {
|
||||
FAILED=$((FAILED+1))
|
||||
echo "Test failed..."
|
||||
exit 42
|
||||
return
|
||||
}
|
||||
|
||||
test::run() {
|
||||
|
@ -17,3 +22,14 @@ test::run() {
|
|||
shift
|
||||
eval "$*" && test::success || test::fail
|
||||
}
|
||||
|
||||
test::finish() {
|
||||
echo
|
||||
if [ $FAILED -gt 0 ]; then
|
||||
echo "${PASSED} tests passed but ${FAILED} failed... :("
|
||||
exit "${FAILED}"
|
||||
else
|
||||
echo "All ${PASSED} tests passed! :)"
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
|
21
test/run
21
test/run
|
@ -4,21 +4,10 @@ set -euo pipefail
|
|||
export SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
source "${SCRIPT_DIR}/test/core.sh"
|
||||
|
||||
check_all_vars() {
|
||||
local arg
|
||||
IFS=$'\n'
|
||||
for var in $(cat "$1" | grep -Eo "<[^>]*>"); do
|
||||
if ! echo "$var" | grep -qE "$ARG_REGEX"; then
|
||||
echoerr "$var isn't a valid variable name!"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
tests="$(find "$SCRIPT_DIR/test" -iname '*_test.sh')"
|
||||
|
||||
test::run "We can find at least one known cheatsheet" \
|
||||
'cheat::find | grep -q "docker.cheat"'
|
||||
|
||||
for cheat in $(cheat::find); do
|
||||
test::run "All variables in $(basename $cheat) are valid" \
|
||||
'check_all_vars "$cheat"'
|
||||
for test in $tests; do
|
||||
source "$test"
|
||||
done
|
||||
|
||||
test::finish
|
||||
|
|
17
test/var_test.sh
Normal file
17
test/var_test.sh
Normal file
|
@ -0,0 +1,17 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
check_all_vars() {
|
||||
local arg
|
||||
IFS=$'\n'
|
||||
for var in $(cat "$1" | grep -Eo "<[^>]*>"); do
|
||||
if ! echo "$var" | grep -qE "$ARG_REGEX"; then
|
||||
echoerr "$var isn't a valid variable name!"
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
for cheat in $(cheat::find); do
|
||||
test::run "All variables in $(basename $cheat) are valid" \
|
||||
'check_all_vars "$cheat"'
|
||||
done
|
Loading…
Reference in a new issue