2 Commits

Author SHA1 Message Date
benvin dfd4efd782 Merge pull request 'Make build-rpm.sh executable and test completion generation' (#2) from benvin/completion-fix into main
ci/woodpecker/tag/release Pipeline was successful
Reviewed-on: #2
2026-08-23 19:00:54 +10:00
unkin-agent a849c26509 Make build-rpm.sh executable and test completion generation
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
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)
2026-08-23 17:29:23 +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