Install shell completion as an optional command

This commit is contained in:
2026-11-03 03:50:12 +00:00
parent 0bed76a6f7
commit fc2f6d5346
9 changed files with 219 additions and 3 deletions

View File

@@ -52,6 +52,9 @@ sys.stdout.write(os.environ['PROBE_REPLY'])
if err := os.WriteFile(filepath.Join(dir, "probe"), []byte(fixture), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(dir, "probe.app"), []byte(fixture), 0o755); err != nil {
t.Fatal(err)
}
if err := os.Mkdir(filepath.Join(dir, "partial dir"), 0o755); err != nil {
t.Fatal(err)
}
@@ -114,6 +117,28 @@ sys.stdout.write(os.environ['PROBE_REPLY'])
}
})
}
t.Run(shell+"/dotted executable", func(t *testing.T) {
var generated bytes.Buffer
if err := CompletionScript(&generated, "probe.app", shell); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(script, generated.Bytes(), 0o644); err != nil {
t.Fatal(err)
}
log := filepath.Join(dir, "log")
if err := os.WriteFile(log, nil, 0o600); err != nil {
t.Fatal(err)
}
cmd := exec.Command("python3", "testdata/completion_terminal.py", shell, script, "probe.app --config=./par")
cmd.Env = append(os.Environ(), "PATH="+dir+string(os.PathListSeparator)+os.Getenv("PATH"), "HOME="+dir, "TERM=xterm", "PROBE_LOG="+log, "PROBE_REPLY="+reply("./partial file\tdescription\n", spfcobra.ShellCompDirectiveNoFileComp), "PROBE_DIR="+dir)
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("shell completion: %v\n%s", err, out)
}
contents, err := os.ReadFile(log)
if err != nil || !strings.Contains(string(contents), `["__complete", "--config=./par"]`) || !strings.Contains(string(contents), `["--config=./partial file"]`) {
t.Fatalf("query and edited line: %q; read error: %v", contents, err)
}
})
}
}