Improve test coverage (#410)

This commit is contained in:
Denis Isidoro 2020-09-15 16:30:30 -03:00 committed by GitHub
parent 2868d178ed
commit 58f85394f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 11 deletions

View File

@ -52,6 +52,9 @@ jobs:
- name: Install fzf
run: git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf; yes | ~/.fzf/install;
- name: Install tmux
run: sudo apt-get install tmux || sudo apt install tmux || brew install tmux
- name: Install tealdeer
run: sudo npm install -g tldr

View File

@ -8,7 +8,7 @@ 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" "$@"
RUST_BACKTRACE=1 NAVI_PATH="${NAVI_TEST_PATH:-$TEST_CHEAT_PATH}" "$navi" "$@"
}
_navi_cases() {
@ -41,6 +41,43 @@ _get_tests() {
fi
}
_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"
}
_navi_widget() {
_navi widget "$1" \
| grep -q "#!/usr/bin/env $1"
}
_navi_cheatspath() {
_navi info cheats-path \
| grep -q "/cheats"
}
_integration() {
local -r log_file="${NAVI_HOME}/target/ci.log"
tmux new-session -d -s ci "export NAVI_TEST_PATH='$(navi info cheats-path)'; $0 _navi repo browse |& tee '${log_file}'"
sleep 5
tmux send-key -t ci denisidoro/cheats; tmux send-key -t ci Enter
sleep 1
tmux send-key -t ci y; tmux send-key -t ci Enter
sleep 6
tmux send-key -t ci pwd
sleep 1
tmux send-key -t ci Enter
sleep 2
cat "$log_file" | tail -n10 | grep -q "/navi"
}
if ! command_exists fzf; then
export PATH="$PATH:$HOME/.fzf/bin"
fi
@ -49,6 +86,13 @@ cd "$NAVI_HOME"
filter="${1:-}"
# TODO: remove this
if [[ $filter == "_navi" ]]; then
shift
_navi "$@"
exit 0
fi
test::set_suite "cases"
ifs="$IFS"
IFS=$'\n'
@ -59,20 +103,25 @@ for i in $(_get_tests "$filter"); do
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::set_suite "widget - bash"
test::run "$query" _navi_widget "bash"
test::set_suite "widget - zsh"
test::run "$query" _navi_widget "zsh"
test::set_suite "widget - fish"
test::run "$query" _navi_widget "fish"
test::set_suite "info - cheats-path"
test::run "$query" _navi_cheatspath
test::set_suite "integration"
test::run "$query" _integration
test::finish