diff --git a/help_test.go b/help_test.go index 0a2d9f97fc..8e9396dc8f 100644 --- a/help_test.go +++ b/help_test.go @@ -1520,3 +1520,68 @@ OPTIONS: output.String(), expected) } } + +func TestCategorizedHelp(t *testing.T) { + // Reset HelpPrinter after this test. + defer func(old helpPrinter) { + HelpPrinter = old + }(HelpPrinter) + + output := new(bytes.Buffer) + app := &App{ + Name: "cli.test", + Writer: output, + Action: func(ctx *Context) error { return nil }, + Flags: []Flag{ + &StringFlag{ + Name: "strd", // no category set + }, + &Int64Flag{ + Name: "intd", + Aliases: []string{"altd1", "altd2"}, + Category: "cat1", + }, + }, + } + + c := NewContext(app, nil, nil) + app.Setup() + + HelpPrinter = func(w io.Writer, templ string, data interface{}) { + funcMap := map[string]interface{}{ + "wrapAt": func() int { + return 30 + }, + } + + HelpPrinterCustom(w, templ, data, funcMap) + } + + _ = ShowAppHelp(c) + + expected := `NAME: + cli.test - A new cli + application + +USAGE: + cli.test [global options] command [command options] [arguments...] + +COMMANDS: + help, h Shows a list of + commands or help + for one command + +GLOBAL OPTIONS: + --help, -h show help + --strd value + + cat1 + + --intd value, --altd1 value, --altd2 value (default: 0) + +` + if output.String() != expected { + t.Errorf("Unexpected wrapping, got:\n%s\nexpected:\n%s", + output.String(), expected) + } +}