Make build-rpm.sh executable and test completion generation
The v0.1.0 tag pipeline failed at the package step: build-rpm.sh was committed mode 100644, so CI's ./scripts/build-rpm.sh invocation died with permission denied before any completions were generated. - Restore the executable bit on scripts/build-rpm.sh (mode 100755, matching node-lookup) - Add TestCompletionAllEntrypointsAndShells covering bash/zsh/fish completion generation through the argv[0] dispatch for all four entrypoints (chlog/chcat/chtail/chgrep)
This commit is contained in:
@@ -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
Reference in New Issue
Block a user