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.
98 lines
2.6 KiB
Bash
Executable File
98 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Runs the completion test suite: builds the task binary, creates a fixture
|
|
# Taskfile with sample files and directories, then exercises the engine and
|
|
# every installed shell wrapper. Skips shells that are not installed.
|
|
set -u
|
|
|
|
here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
root=$(cd "$here/../.." && pwd)
|
|
|
|
# Temp dirs for the binary and the fixture; removed on exit (including on early
|
|
# failure via the trap).
|
|
bindir=$(mktemp -d)
|
|
fixture=$(mktemp -d)
|
|
trap 'rm -rf "$bindir" "$fixture"' EXIT
|
|
|
|
# Build the binary under test.
|
|
if ! go build -o "$bindir/task" "$root/cmd/task"; then
|
|
echo "failed to build task binary" >&2
|
|
exit 1
|
|
fi
|
|
export TASK_BIN="$bindir/task"
|
|
# fish and PowerShell register completion for the command name `task`, so make
|
|
# `task` on PATH resolve to the binary under test.
|
|
export PATH="$bindir:$PATH"
|
|
|
|
# Fixture: a Taskfile plus files/dirs so file/dir completion has real entries.
|
|
cat > "$fixture/Taskfile.yml" <<'YML'
|
|
version: '3'
|
|
|
|
tasks:
|
|
build:
|
|
desc: Build it
|
|
deploy:
|
|
desc: Deploy it
|
|
aliases: [dep]
|
|
requires:
|
|
vars:
|
|
- name: ENV
|
|
enum: [dev, prod]
|
|
- REGION
|
|
docs:serve:
|
|
desc: Serve docs
|
|
YML
|
|
touch "$fixture/extra.yaml" "$fixture/notes.txt"
|
|
mkdir -p "$fixture/sub" "$fixture/other"
|
|
export TASK_FIXTURE="$fixture"
|
|
|
|
# In strict mode (set TASK_COMPLETION_STRICT=1, used in CI) a missing shell is
|
|
# a failure instead of a skip, so we never get a false pass when a shell the
|
|
# environment was expected to provide (e.g. pwsh on CI runners) is absent.
|
|
strict=${TASK_COMPLETION_STRICT:-}
|
|
|
|
fails=0
|
|
run() { # LABEL COMMAND...
|
|
echo "== $1 =="
|
|
if "${@:2}"; then :; else fails=$((fails + 1)); fi
|
|
echo
|
|
}
|
|
skip() { # LABEL
|
|
if [[ -n "$strict" ]]; then
|
|
echo "== $1 == (MISSING — required under TASK_COMPLETION_STRICT)"
|
|
fails=$((fails + 1))
|
|
else
|
|
echo "== $1 == (skipped: not installed)"
|
|
fi
|
|
echo
|
|
}
|
|
|
|
# The engine/protocol itself is covered by the Go tests (completion/protocol_test.go
|
|
# and internal/complete); these smokes only check how each shell wrapper
|
|
# interprets the directive.
|
|
run "bash wrapper" bash "$here/wrapper.bash"
|
|
|
|
if command -v zsh >/dev/null 2>&1; then
|
|
run "zsh wrapper" zsh "$here/wrapper.zsh"
|
|
else
|
|
skip "zsh wrapper"
|
|
fi
|
|
|
|
if command -v fish >/dev/null 2>&1; then
|
|
run "fish wrapper" fish "$here/wrapper.fish"
|
|
else
|
|
skip "fish wrapper"
|
|
fi
|
|
|
|
pwsh_bin=$(command -v pwsh || command -v pwsh-preview || true)
|
|
if [[ -n "$pwsh_bin" ]]; then
|
|
run "powershell wrapper" "$pwsh_bin" -NoProfile -File "$here/wrapper.ps1"
|
|
else
|
|
skip "powershell wrapper"
|
|
fi
|
|
|
|
if ((fails)); then
|
|
echo "completion tests: $fails suite(s) failed"
|
|
exit 1
|
|
fi
|
|
echo "completion tests: all suites passed"
|