mirror of
https://github.com/go-task/task.git
synced 2026-07-10 04:22:03 +02:00
Follow cobra's testing philosophy: the completion protocol (candidates + directive) is business logic and belongs in Go, while the shell wrappers only need to be checked for how they interpret each directive. - Add completion/protocol_test.go: a table-driven black-box test that runs the real `task __complete` binary and asserts the offered values and the emitted directive. Unlike the in-process engine tests, it exercises the actual entrypoint dispatch, runComplete wiring and — crucially — the real flag set, so it catches drift between the completion enum/directive maps and the flag definitions. Runs on every OS, including Windows where the shell smokes don't. - Delete completion/tests/engine.sh (the protocol is now covered in Go) and drop it from run.sh. - Reduce the bash/zsh/fish/powershell smokes to directive routing only (files vs dirs vs no-files vs no-space), removing the task/alias/var assertions that the Go tests already own.
82 lines
2.4 KiB
Bash
Executable File
82 lines
2.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Smoke-tests how the bash wrapper INTERPRETS each directive by stubbing the
|
|
# bash-completion helpers it calls (_filedir / compopt / __ltrim_colon_completions)
|
|
# and asserting the routing. The suggestion logic (which tasks/aliases/vars) is
|
|
# covered by the Go tests; here we only check that each directive triggers the
|
|
# right shell behavior. Deterministic, no TTY, works without bash-completion.
|
|
#
|
|
# Requires: TASK_BIN (task binary), TASK_FIXTURE (dir with a Taskfile.yml).
|
|
set -u
|
|
|
|
: "${TASK_BIN:?}"; : "${TASK_FIXTURE:?}"
|
|
export TASK_EXE="$TASK_BIN"
|
|
cd "$TASK_FIXTURE" || exit 1
|
|
|
|
fails=0
|
|
CAP=""
|
|
|
|
# Stubs standing in for the bash-completion runtime.
|
|
_init_completion() {
|
|
words=("${TEST_WORDS[@]}")
|
|
cword=$TEST_CWORD
|
|
cur="${TEST_WORDS[$TEST_CWORD]}"
|
|
prev="${TEST_WORDS[$((TEST_CWORD - 1))]}"
|
|
return 0
|
|
}
|
|
_filedir() { CAP+="filedir:$*"$'\n'; }
|
|
compopt() { CAP+="compopt:$*"$'\n'; }
|
|
__ltrim_colon_completions() { :; }
|
|
|
|
source "$(dirname "${BASH_SOURCE[0]}")/../bash/task.bash"
|
|
|
|
run() {
|
|
CAP=""
|
|
TEST_WORDS=("$@")
|
|
TEST_CWORD=$((${#TEST_WORDS[@]} - 1))
|
|
COMPREPLY=()
|
|
_task
|
|
}
|
|
|
|
reply_has() { # LABEL VALUE
|
|
local v
|
|
for v in "${COMPREPLY[@]}"; do [[ "$v" == "$2" ]] && { echo " ok $1"; return; }; done
|
|
echo " FAIL $1 — '$2' missing from COMPREPLY: ${COMPREPLY[*]}"
|
|
fails=$((fails + 1))
|
|
}
|
|
cap_has() { # LABEL PATTERN
|
|
if [[ "$CAP" == *"$2"* ]]; then echo " ok $1"; else
|
|
echo " FAIL $1 — expected '$2' in: $CAP"; fails=$((fails + 1)); fi
|
|
}
|
|
cap_hasnot() { # LABEL PATTERN
|
|
if [[ "$CAP" == *"$2"* ]]; then
|
|
echo " FAIL $1 — '$2' should be absent in: $CAP"; fails=$((fails + 1)); else
|
|
echo " ok $1"; fi
|
|
}
|
|
|
|
echo "bash: :4 (NoFileComp) forwards candidates, no file fallback"
|
|
run task ''
|
|
reply_has "candidate forwarded" build
|
|
cap_hasnot "no file fallback" "filedir:"
|
|
|
|
echo "bash: :2 (NoSpace) disables the trailing space"
|
|
run task deploy ''
|
|
cap_has "nospace applied" "compopt:-o nospace"
|
|
|
|
echo "bash: :8 (FilterFileExt) routes to extension-filtered files"
|
|
run task --taskfile ''
|
|
cap_has "filedir ext glob" "filedir:@(yml|yaml)"
|
|
|
|
echo "bash: :16 (FilterDirs) routes to directory completion"
|
|
run task --dir ''
|
|
cap_has "filedir -d" "filedir:-d"
|
|
|
|
echo "bash: :0 (Default) falls back to files"
|
|
run task build -- ''
|
|
cap_has "filedir default" "filedir:"
|
|
|
|
if ((fails)); then
|
|
echo "bash: $fails failure(s)"
|
|
exit 1
|
|
fi
|
|
echo "bash: all passed"
|