Skip to content

Commit

Permalink
Improve test coverage (#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
denisidoro authored Sep 15, 2020
1 parent 2868d17 commit 58f8539
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
71 changes: 60 additions & 11 deletions tests/run
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -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'
Expand All @@ -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

0 comments on commit 58f8539

Please sign in to comment.