2020-03-19 12:19:50 +00:00
|
|
|
#!/usr/bin/env bash
|
2020-09-15 21:45:40 +00:00
|
|
|
set -euo pipefail
|
2020-03-19 12:19:50 +00:00
|
|
|
|
|
|
|
export NAVI_HOME="$(cd "$(dirname "$0")/.." && pwd)"
|
|
|
|
source "${NAVI_HOME}/tests/core.bash"
|
|
|
|
|
2020-09-15 21:45:40 +00:00
|
|
|
export TEST_CHEAT_PATH="${NAVI_HOME}/tests/no_prompt_cheats"
|
|
|
|
export NAVI_EXE="${NAVI_HOME}/target/debug/navi"
|
|
|
|
|
|
|
|
if ! command_exists navi; then
|
|
|
|
navi() {
|
|
|
|
"$NAVI_EXE" "$@"
|
|
|
|
}
|
|
|
|
export -f navi
|
|
|
|
fi
|
2020-03-19 12:19:50 +00:00
|
|
|
|
|
|
|
_navi() {
|
|
|
|
stty sane || true
|
2020-09-15 19:38:28 +00:00
|
|
|
RUST_BACKTRACE=1 NAVI_PATH="${NAVI_TEST_PATH:-$TEST_CHEAT_PATH}" "$NAVI_EXE" "$@"
|
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"
|
|
|
|
}
|
|
|
|
|
2020-09-15 21:45:40 +00:00
|
|
|
_kill_tmux() {
|
|
|
|
pkill -f tmux 2>/dev/null || true
|
|
|
|
}
|
|
|
|
|
|
|
|
_assert_tmux() {
|
|
|
|
local -r log_file="$1"
|
|
|
|
local -r sessions="$(tmux list-sessions)"
|
|
|
|
if [ -z "$sessions" ]; then
|
|
|
|
_kill_tmux
|
|
|
|
cat "$log_file"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-09-15 19:30:30 +00:00
|
|
|
_integration() {
|
2020-09-15 21:45:40 +00:00
|
|
|
_kill_tmux
|
2020-09-15 19:30:30 +00:00
|
|
|
local -r log_file="${NAVI_HOME}/target/ci.log"
|
2020-09-15 21:45:40 +00:00
|
|
|
local -r cheats_path="$($NAVI_EXE info cheats-path)"
|
|
|
|
mkdir -p "$cheats_path" 2>/dev/null || true
|
|
|
|
local -r bak_cheats_path="$(mktemp -d "${cheats_path}_XXXXX")"
|
|
|
|
rm "$log_file" 2>/dev/null || true
|
|
|
|
mv "$cheats_path" "$bak_cheats_path" 2>/dev/null || true
|
|
|
|
|
|
|
|
echoerr "Starting sessions..."
|
|
|
|
tmux new-session -d -s ci "export NAVI_TEST_PATH='${cheats_path}'; ${NAVI_HOME}/tests/run _navi |& tee '${log_file}'"
|
2020-09-15 19:30:30 +00:00
|
|
|
sleep 5
|
2020-09-15 21:45:40 +00:00
|
|
|
_assert_tmux "$log_file"
|
|
|
|
|
|
|
|
echoerr "Downloading default cheatsheets..."
|
|
|
|
tmux send-key -t ci "download default"; tmux send-key -t ci "Enter"
|
2020-09-15 19:30:30 +00:00
|
|
|
sleep 1
|
2020-09-15 21:45:40 +00:00
|
|
|
_assert_tmux "$log_file"
|
|
|
|
|
|
|
|
echoerr "Confirming import..."
|
|
|
|
tmux send-key -t ci "y"; tmux send-key -t ci "Enter"
|
2020-09-15 19:30:30 +00:00
|
|
|
sleep 6
|
2020-09-15 21:45:40 +00:00
|
|
|
_assert_tmux "$log_file"
|
|
|
|
|
|
|
|
echoerr "Running snippet..."
|
|
|
|
tmux send-key -t ci "pwd"
|
|
|
|
sleep 1
|
|
|
|
tmux send-key -t ci "Enter"
|
2020-09-15 19:30:30 +00:00
|
|
|
|
|
|
|
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-09-15 21:45:40 +00:00
|
|
|
test::set_suite "3rd party"
|
|
|
|
test::run "tldr" _navi_tldr
|
|
|
|
test::run "cheatsh" _navi_cheatsh
|
2020-09-15 19:30:30 +00:00
|
|
|
|
2020-09-15 21:45:40 +00:00
|
|
|
test::set_suite "widget"
|
|
|
|
test::run "bash" _navi_widget "bash"
|
|
|
|
test::run "zsh" _navi_widget "zsh"
|
|
|
|
test::run "zsh" _navi_widget "fish"
|
2020-09-15 19:30:30 +00:00
|
|
|
|
2020-09-15 21:45:40 +00:00
|
|
|
test::set_suite "info"
|
|
|
|
test::run "cheats_path" _navi_cheatspath
|
2020-09-15 19:30:30 +00:00
|
|
|
|
|
|
|
test::set_suite "integration"
|
2020-09-15 21:45:40 +00:00
|
|
|
test::run "welcome->pwd" _integration
|
2020-09-15 19:30:30 +00:00
|
|
|
|
2020-04-16 12:40:11 +00:00
|
|
|
test::finish
|