mirror of
https://github.com/Cheviiot/Vintner.git
synced 2026-08-03 15:57:24 +00:00
vintner completion bash|zsh prints a completion script meant to be sourced (source <(vintner completion bash)); completes subcommands (including short aliases), download's flags, and directory arguments for install/env --bin. Mentioned in the top-level usage text and documented in the README. The Nivora package doesn't auto-install these system-wide yet - it'd need Stapler's install-completion helper, whose calling convention isn't documented anywhere in this repo or Nivora's other packages, so guessing at it risked a broken package build for a nice-to-have. source <(vintner completion bash) works today regardless of install method (Nivora, prebuilt binary, or from source).
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"os/exec"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestCompletionScriptsAreSyntacticallyValid catches the easy way to break
|
|
// these: a typo in the hand-maintained flag lists that produces invalid
|
|
// shell syntax. It shells out to bash/zsh -n rather than parsing the script
|
|
// itself, so it's testing exactly what a user's shell would see.
|
|
func TestCompletionScriptsAreSyntacticallyValid(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
shell string
|
|
script string
|
|
}{
|
|
{"bash", bashCompletionScript},
|
|
{"zsh", zshCompletionScript},
|
|
} {
|
|
t.Run(tc.shell, func(t *testing.T) {
|
|
if _, err := exec.LookPath(tc.shell); err != nil {
|
|
t.Skipf("%s not installed", tc.shell)
|
|
}
|
|
cmd := exec.Command(tc.shell, "-n", "/dev/stdin")
|
|
cmd.Stdin = strings.NewReader(tc.script)
|
|
if out, err := cmd.CombinedOutput(); err != nil {
|
|
t.Fatalf("%s -n rejected the completion script: %v\n%s", tc.shell, err, out)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestRunCompletionUnknownShell(t *testing.T) {
|
|
if code := runCompletion([]string{"fish"}); code != 1 {
|
|
t.Errorf("runCompletion([\"fish\"]) = %d, want 1", code)
|
|
}
|
|
if code := runCompletion(nil); code != 1 {
|
|
t.Errorf("runCompletion(nil) = %d, want 1", code)
|
|
}
|
|
if code := runCompletion([]string{"bash", "extra"}); code != 1 {
|
|
t.Errorf("runCompletion with extra arg = %d, want 1", code)
|
|
}
|
|
}
|