Skip to content

Commit

Permalink
Add new test
Browse files Browse the repository at this point in the history
  • Loading branch information
skelouse committed Jan 29, 2023
1 parent 75a20d4 commit 31d7502
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 31d7502

Please sign in to comment.