refactor(bonfire): run the root without fang so bonfire's root help stays installed (IN-06, quick-261028-rqd)

This commit is contained in:
Jakub Zych
2026-10-28 20:26:20 +01:00
parent 39c59b8329
commit 53c0a65a43
6 changed files with 51 additions and 39 deletions

View File

@@ -103,3 +103,28 @@ func TestCallNoGlobalsHook(t *testing.T) {
t.Error("a nil Catalog has commands")
}
}
// TestExecuteKeepsRootHelp (IN-06): after Execute the root's help function
// is still bonfire's list renderer, not one Execute installed.
func TestExecuteKeepsRootHelp(t *testing.T) {
plainEnv(t)
commands := []Command{{Name: "acme:ok", Description: "Succeed", Run: func(context.Context, Input, Output) error { return nil }}}
var buf bytes.Buffer
root, err := NewRootIO("acme", commands, strings.NewReader(""), &buf, &buf, WithVersion(goldenVersion))
if err != nil {
t.Fatal(err)
}
if code := Execute(context.Background(), root, nil); code != ExitOK {
t.Fatalf("Execute: exit %d\n%s", code, buf.String())
}
want := buf.String()
buf.Reset()
if code := Execute(context.Background(), root, []string{"list"}); code != ExitOK {
t.Fatalf("Execute list: exit %d\n%s", code, buf.String())
}
buf.Reset()
root.HelpFunc()(root, nil)
if got := buf.String(); got != want {
t.Errorf("root help after Execute:\n%s\nwant the command list:\n%s", got, want)
}
}