summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDenis Isidoro <denisidoro@users.noreply.github.com>2020-08-28 09:58:35 -0300
committerGitHub <noreply@github.com>2020-08-28 09:58:35 -0300
commitd64ec34912c5aa91852c78d6cbf7524f30768e6d (patch)
tree30cb44f183da293c094971a037bba736a4eb0fc6 /tests
parent84273c129c362d09f62cbf8bf69867231c1c05b9 (diff)
Improve test coverage (#390)
- add test for tldr and cheatsh - run all possible test cases
Diffstat (limited to 'tests')
-rw-r--r--tests/no_prompt_cheats/cases.cheat4
-rwxr-xr-xtests/run32
2 files changed, 28 insertions, 8 deletions
diff --git a/tests/no_prompt_cheats/cases.cheat b/tests/no_prompt_cheats/cases.cheat
index d60e859..fb73acb 100644
--- a/tests/no_prompt_cheats/cases.cheat
+++ b/tests/no_prompt_cheats/cases.cheat
@@ -31,8 +31,8 @@ echo "lorem <multiword> ipsum"
# variable dependency, full -> "2 12 a 2"
echo "<x> <x2> <y> <x>"
-# variable dependency, we can ignore intermediate values -> "12"
-: <x>; echo "<x2>"
+; # variable dependency, we can ignore intermediate values -> "foo 12"
+; printf "foo "; : <x>; echo "<x2>"
# nested unused value -> "path: /my/pictures"
echo "path: <pictures_folder>"
diff --git a/tests/run b/tests/run
index fda030f..1e65993 100755
--- a/tests/run
+++ b/tests/run
@@ -8,19 +8,23 @@ TEST_CHEAT_PATH="${NAVI_HOME}/tests/no_prompt_cheats"
_navi() {
stty sane || true
local -r navi="./target/debug/navi"
+ RUST_BACKTRACE=1 NAVI_PATH="$TEST_CHEAT_PATH" "$navi" "$@"
+}
+
+_navi_cases() {
local filter="$*"
- local filter="${filter::-2}"
- RUST_BACKTRACE=1 NAVI_PATH="$TEST_CHEAT_PATH" "$navi" best "$filter"
+ filter="${filter::-2}"
+ _navi --query "$filter" --best-match
}
-_navi_test() {
- _navi "$1" \
+_navi_cases_test() {
+ _navi_cases "$1" \
| test::equals "$2"
}
_get_all_tests() {
cat "${TEST_CHEAT_PATH}/cases.cheat" \
- | grep '#' \
+ | grep '^#' \
| grep ' ->' \
| sed 's/\\n/ /g' \
| sed -E 's/# (.*) -> "(.*)"/\1|\2/g'
@@ -52,7 +56,23 @@ for i in $(_get_tests "$filter"); do
IFS="$ifs"
query="$(echo "$i" | cut -d'|' -f1)"
expected="$(echo "$i" | cut -d'|' -f2)"
- test::run "$query" _navi_test "$query" "$expected"
+ test::run "$query" _navi_cases_test "$query" "$expected"
done
+_navi_tldr() {
+ _navi --tldr docker --query ps --print --best-match \
+ | test::equals "docker ps"
+}
+
+_navi_cheatsh() {
+ _navi --cheatsh docker --query remove --print --best-match \
+ | test::equals "docker rm container_name"
+}
+
+test::set_suite "tldr"
+test::run "$query" _navi_tldr
+
+test::set_suite "cheatsh"
+test::run "$query" _navi_cheatsh
+
test::finish