Make build-rpm.sh executable and test completion generation #2

Merged
benvin merged 1 commits from benvin/completion-fix into main 2026-08-23 19:00:54 +10:00
2 changed files with 27 additions and 0 deletions
+27
View File
@@ -1,6 +1,7 @@
package main
import (
"os"
"strings"
"testing"
"time"
@@ -82,6 +83,32 @@ func TestGrepGuardAllowsShortWindow(t *testing.T) {
}
}
func TestCompletionAllEntrypointsAndShells(t *testing.T) {
// scripts/build-rpm.sh runs "<name> completion <shell>" for every
// entrypoint; guard that each argv[0]-dispatched command tree exposes a
// working completion subcommand for all three packaged shells.
for _, name := range []string{"chlog", "chcat", "chtail", "chgrep"} {
for _, shell := range []string{"bash", "zsh", "fish"} {
t.Run(name+"/"+shell, func(t *testing.T) {
orig := os.Args
os.Args = []string{name}
defer func() { os.Args = orig }()
cmd := entrypoint()
var out strings.Builder
cmd.SetOut(&out)
cmd.SetErr(&out)
cmd.SetArgs([]string{"completion", shell})
if err := cmd.Execute(); err != nil {
t.Fatalf("%s completion %s: %v", name, shell, err)
}
if !strings.Contains(out.String(), name) {
t.Fatalf("%s completion %s output does not mention %q", name, shell, name)
}
})
}
}
}
func TestEntrypointDispatch(t *testing.T) {
root := newRootCmd()
names := map[string]bool{}
Regular → Executable
View File