2020-03-19 12:19:50 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
export NAVI_HOME="$(cd "$(dirname "$0")/.." && pwd)"
|
|
|
|
source "${NAVI_HOME}/tests/core.bash"
|
|
|
|
|
|
|
|
TEST_CHEAT_PATH="${NAVI_HOME}/tests/no_prompt_cheats"
|
|
|
|
|
|
|
|
_navi() {
|
|
|
|
stty sane || true
|
|
|
|
local -r navi="./target/debug/navi"
|
2020-09-15 19:30:30 +00:00
|
|
|
RUST_BACKTRACE=1 NAVI_PATH="${NAVI_TEST_PATH:-$TEST_CHEAT_PATH}" "$navi" "$@"
|
2020-08-28 12:58:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_navi_cases() {
|
2020-03-19 12:19:50 +00:00
|
|
|
local filter="$*"
|
2020-08-28 12:58:35 +00:00
|
|
|
filter="${filter::-2}"
|
|
|
|
_navi --query "$filter" --best-match
|
2020-03-19 12:19:50 +00:00
|
|
|
}
|
|
|
|
|
2020-08-28 12:58:35 +00:00
|
|
|
_navi_cases_test() {
|
|
|
|
_navi_cases "$1" \
|
2020-03-19 12:19:50 +00:00
|
|
|
| test::equals "$2"
|
|
|
|
}
|
|
|
|
|
|
|
|
_get_all_tests() {
|
|
|
|
cat "${TEST_CHEAT_PATH}/cases.cheat" \
|
2020-08-28 12:58:35 +00:00
|
|
|
| grep '^#' \
|
2020-03-19 12:19:50 +00:00
|
|
|
| grep ' ->' \
|
|
|
|
| sed 's/\\n/ /g' \
|
|
|
|
| sed -E 's/# (.*) -> "(.*)"/\1|\2/g'
|
|
|
|
}
|
|
|
|
|
|
|
|
_get_tests() {
|
|
|
|
local -r filter="$1"
|
|
|
|
|
|
|
|
if [ -n "$filter" ]; then
|
|
|
|
_get_all_tests \
|
|
|
|
| grep "$filter"
|
|
|
|
else
|
|
|
|
_get_all_tests
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-09-15 19:30:30 +00:00
|
|
|
_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"
|
|
|
|
}
|
|
|
|
|
2020-03-19 12:19:50 +00:00
|
|
|
if ! command_exists fzf; then
|
|
|
|
export PATH="$PATH:$HOME/.fzf/bin"
|
|
|
|
fi
|
|
|
|
|
|
|
|
cd "$NAVI_HOME"
|
|
|
|
|
|
|
|
filter="${1:-}"
|
|
|
|
|
2020-09-15 19:30:30 +00:00
|
|
|
# TODO: remove this
|
|
|
|
if [[ $filter == "_navi" ]]; then
|
|
|
|
shift
|
|
|
|
_navi "$@"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2020-03-19 12:19:50 +00:00
|
|
|
test::set_suite "cases"
|
|
|
|
ifs="$IFS"
|
|
|
|
IFS=$'\n'
|
|
|
|
for i in $(_get_tests "$filter"); do
|
|
|
|
IFS="$ifs"
|
|
|
|
query="$(echo "$i" | cut -d'|' -f1)"
|
|
|
|
expected="$(echo "$i" | cut -d'|' -f2)"
|
2020-08-28 12:58:35 +00:00
|
|
|
test::run "$query" _navi_cases_test "$query" "$expected"
|
2020-03-19 12:19:50 +00:00
|
|
|
done
|
|
|
|
|
2020-08-28 12:58:35 +00:00
|
|
|
test::set_suite "tldr"
|
|
|
|
test::run "$query" _navi_tldr
|
|
|
|
|
|
|
|
test::set_suite "cheatsh"
|
|
|
|
test::run "$query" _navi_cheatsh
|
|
|
|
|
2020-09-15 19:30:30 +00:00
|
|
|
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
|
|
|
|
|
2020-04-16 12:40:11 +00:00
|
|
|
test::finish
|