mirror of
https://github.com/denisidoro/navi
synced 2024-11-22 03:23:05 +00:00
Improve test runner (#41)
This commit is contained in:
parent
be92d158ad
commit
b3f8e0b374
9 changed files with 60 additions and 34 deletions
2
navi
2
navi
|
@ -28,7 +28,7 @@ source "${SCRIPT_DIR}/src/main.sh"
|
||||||
##? cheats query git
|
##? cheats query git
|
||||||
##?
|
##?
|
||||||
##? More info:
|
##? More info:
|
||||||
##? search
|
##? search
|
||||||
##? Queries cheatsheets from http://cheat.sh
|
##? Queries cheatsheets from http://cheat.sh
|
||||||
##? Please note that these cheatsheets may not work out of the box
|
##? Please note that these cheatsheets may not work out of the box
|
||||||
##? Always check the preview window before executing commands!
|
##? Always check the preview window before executing commands!
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
cheat::find() {
|
cheat::find() {
|
||||||
for path in $(echo "$NAVI_PATH" | tr ':' '\n'); do
|
for path in $(echo "$NAVI_PATH" | tr ':' '\n'); do
|
||||||
find "$path" -iname '*.cheat'
|
find "$path" -iname '*.cheat'
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
cheat::read_many() {
|
cheat::read_many() {
|
||||||
|
|
16
src/main.sh
16
src/main.sh
|
@ -52,18 +52,18 @@ handler::preview() {
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
case ${entry_point:-} in
|
case ${entry_point:-} in
|
||||||
preview)
|
preview)
|
||||||
handler::preview "$@" \
|
handler::preview "$@" \
|
||||||
|| echo "Unable to find command for '${query:-}'"
|
|| echo "Unable to find command for '${query:-}'"
|
||||||
;;
|
;;
|
||||||
search)
|
search)
|
||||||
health::fzf
|
health::fzf
|
||||||
search::save "$query" || true
|
search::save "$query" || true
|
||||||
handler::main "$@"
|
handler::main "$@"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
health::fzf
|
health::fzf
|
||||||
handler::main "$@"
|
handler::main "$@"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
|
@ -40,9 +40,9 @@ opts::eval() {
|
||||||
--command-for) wait_for="command-for" ;;
|
--command-for) wait_for="command-for" ;;
|
||||||
--no-preview) preview=false ;;
|
--no-preview) preview=false ;;
|
||||||
--path) wait_for="path" ;;
|
--path) wait_for="path" ;;
|
||||||
search) entry_point="search"; wait_for="search";;
|
search) entry_point="search"; wait_for="search" ;;
|
||||||
preview) entry_point="preview"; wait_for="preview";;
|
preview) entry_point="preview"; wait_for="preview" ;;
|
||||||
q|query) wait_for="query";;
|
q|query) wait_for="query" ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ search::save() {
|
||||||
|
|
||||||
local readonly filepath="$(search::full_path "$cmd")"
|
local readonly filepath="$(search::full_path "$cmd")"
|
||||||
local readonly filedir="$(dirname "$filepath")"
|
local readonly filedir="$(dirname "$filepath")"
|
||||||
|
|
||||||
if [ -f "$filepath" ]; then
|
if [ -f "$filepath" ]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
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"'
|
20
test/core.sh
20
test/core.sh
|
@ -2,13 +2,18 @@
|
||||||
|
|
||||||
source "${SCRIPT_DIR}/src/main.sh"
|
source "${SCRIPT_DIR}/src/main.sh"
|
||||||
|
|
||||||
|
PASSED=0
|
||||||
|
FAILED=0
|
||||||
|
|
||||||
test::success() {
|
test::success() {
|
||||||
|
PASSED=$((PASSED+1))
|
||||||
echo "Test passed!"
|
echo "Test passed!"
|
||||||
}
|
}
|
||||||
|
|
||||||
test::fail() {
|
test::fail() {
|
||||||
|
FAILED=$((FAILED+1))
|
||||||
echo "Test failed..."
|
echo "Test failed..."
|
||||||
exit 42
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
test::run() {
|
test::run() {
|
||||||
|
@ -16,4 +21,15 @@ test::run() {
|
||||||
echo "-> $1"
|
echo "-> $1"
|
||||||
shift
|
shift
|
||||||
eval "$*" && test::success || test::fail
|
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)"
|
export SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||||
source "${SCRIPT_DIR}/test/core.sh"
|
source "${SCRIPT_DIR}/test/core.sh"
|
||||||
|
|
||||||
check_all_vars() {
|
tests="$(find "$SCRIPT_DIR/test" -iname '*_test.sh')"
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
test::run "We can find at least one known cheatsheet" \
|
for test in $tests; do
|
||||||
'cheat::find | grep -q "docker.cheat"'
|
source "$test"
|
||||||
|
|
||||||
for cheat in $(cheat::find); do
|
|
||||||
test::run "All variables in $(basename $cheat) are valid" \
|
|
||||||
'check_all_vars "$cheat"'
|
|
||||||
done
|
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