Files
task/completion/tests/wrapper.ps1
Valentin Maerten ed7a206e19 feat(completion): unify shell completions behind an opt-in task __complete engine
Bash, Fish, Zsh, Nushell and PowerShell now share a single backend: `task __complete` returns the suggestions plus a directive, and every wrapper is a thin shim around it. All five shells offer the same suggestions — task names, aliases, flags, flag values and per-task CLI variables. The Zsh `show-aliases` and `verbose` zstyles keep working, now backed by the `--no-aliases` and `--no-descriptions` completion flags.

The engine is opt-in via `task --new-completion <shell>`, leaving `--completion` and the legacy scripts untouched; it will become the default in a future release. The new wrappers live under `completion/next/`.

Completing a keystroke never reaches the network, never blocks on a stdin entrypoint, and honors every flag that decides how the Taskfile is loaded. Ref resolution shared by `requires` and enum completion moved to `internal/refs`.

A cross-shell test suite exercises the protocol in Go with thin shell smoke tests, and runs in CI.
2026-08-20 14:18:54 +02:00

68 lines
2.3 KiB
PowerShell

# Smoke-tests how the PowerShell wrapper routes each directive, via the
# completion API. Set up by run.sh: $env:TASK_FIXTURE, and `task` on PATH =
# the binary under test.
Set-Location $env:TASK_FIXTURE
. "$PSScriptRoot/../next/ps/task.ps1"
$fails = 0
function Cands($line) {
([System.Management.Automation.CommandCompletion]::CompleteInput($line, $line.Length, $null)).CompletionMatches |
ForEach-Object { $_.CompletionText }
}
function Has($label, $line, $value) {
if ((Cands $line) -contains $value) {
Write-Output " ok $label"
} else {
Write-Output " FAIL $label — '$value' missing from: $((Cands $line) -join ' ')"
$script:fails++
}
}
function HasNot($label, $line, $value) {
if ((Cands $line) -contains $value) {
Write-Output " FAIL $label — '$value' should be absent"
$script:fails++
} else {
Write-Output " ok $label"
}
}
Write-Output "powershell: :4 (NoFileComp) forwards candidates, offers no files"
Has "candidate forwarded" 'task ' 'build'
HasNot "no file fallback" 'task ' 'notes.txt'
Write-Output "powershell: filters candidates by the current word"
Has "prefix keeps match" 'task b' 'build'
HasNot "prefix drops others" 'task b' 'deploy'
Write-Output "powershell: :16 (FilterDirs) offers directories only"
Has "dir offered" 'task --dir ' 'sub'
HasNot "no plain file" 'task --dir ' 'notes.txt'
Write-Output "powershell: :8 (FilterFileExt) filters by extension"
Has "matching file" 'task --taskfile ' 'Taskfile.yml'
HasNot "non-matching file" 'task --taskfile ' 'notes.txt'
Write-Output "powershell: nested path completion keeps the directory prefix"
Has "prefix kept" 'task --taskfile sub/' 'sub/nested.yml'
Write-Output "powershell: inline --flag=path keeps the --flag= prefix"
Has "inline nested" 'task --taskfile=sub/' '--taskfile=sub/nested.yml'
HasNot "inline non-matching" 'task --taskfile=' '--taskfile=notes.txt'
Write-Output "powershell: a quoted argument reaches the engine unquoted"
Has "single-quoted dir" "task --dir 'with space' " 'spaced'
Has "double-quoted dir" 'task --dir "with space" ' 'spaced'
Write-Output "powershell: a candidate holding a space is quoted for insertion"
Has "dir quoted" 'task --dir w' "'with space'"
if ($fails -ne 0) {
Write-Output "powershell: $fails failure(s)"
exit 1
}
Write-Output "powershell: all passed"