Skip to content

Commit

Permalink
Make test case more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
dearchap committed Aug 25, 2022
1 parent 915fd7a commit e01afb2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
1 change: 0 additions & 1 deletion help.go
Expand Up @@ -297,7 +297,6 @@ func printHelpCustom(out io.Writer, templ string, data interface{}, customFuncs
funcMap := template.FuncMap{
"join": strings.Join,
"subtract": subtract,
"add": add,
"indent": indent,
"nindent": nindent,
"trim": strings.TrimSpace,
Expand Down
15 changes: 11 additions & 4 deletions help_test.go
Expand Up @@ -907,6 +907,11 @@ App UsageText`,
Aliases: []string{"frb1", "frbb2", "frl2"},
Usage: "this is a long help output for the run command, long usage \noutput, long usage output, long usage output, long usage output\noutput, long usage output, long usage output",
},
{
Name: "grobbly",
Aliases: []string{"grb1", "grbb2"},
Usage: "this is another long help output for the run command, long usage \noutput, long usage output",
},
},
}

Expand All @@ -915,10 +920,12 @@ App UsageText`,

_ = app.Run([]string{"foo"})

expected := `frobbly, frb1, frbb2, frl2 this is a long help output for the run command, long usage
output, long usage output, long usage output, long usage output
output, long usage output, long usage output`

expected := "COMMANDS:\n" +
" frobbly, frb1, frbb2, frl2 this is a long help output for the run command, long usage \n" +
" output, long usage output, long usage output, long usage output\n" +
" output, long usage output, long usage output\n" +
" grobbly, grb1, grbb2 this is another long help output for the run command, long usage \n" +
" output, long usage output"
if !strings.Contains(output.String(), expected) {
t.Errorf("expected output to include usage text; got: %q", output.String())
}
Expand Down
4 changes: 2 additions & 2 deletions template.go
Expand Up @@ -22,7 +22,7 @@ AUTHOR{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}:
COMMANDS:{{range .VisibleCategories}}{{if .Name}}
{{.Name}}:{{range .VisibleCommands}}
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{ $cv := offsetCommands .VisibleCommands 5}}{{range .VisibleCommands}}
{{$s := join .Names ", "}}{{$s}}{{ $sp := subtract $cv (add (len $s) 3) }}{{ indent $sp ""}}{{wrap .Usage $cv}}{{end}}{{end}}{{end}}{{end}}{{if .VisibleFlagCategories}}
{{$s := join .Names ", "}}{{$s}}{{ $sp := subtract $cv (offset $s 3) }}{{ indent $sp ""}}{{wrap .Usage $cv}}{{end}}{{end}}{{end}}{{end}}{{if .VisibleFlagCategories}}
GLOBAL OPTIONS:{{range .VisibleFlagCategories}}
{{if .Name}}{{.Name}}
Expand Down Expand Up @@ -77,7 +77,7 @@ DESCRIPTION:
COMMANDS:{{range .VisibleCategories}}{{if .Name}}
{{.Name}}:{{range .VisibleCommands}}
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{ $cv := offsetCommands .VisibleCommands 5}}{{range .VisibleCommands}}
{{$s := join .Names ", "}}{{$s}}{{ $sp := subtract $cv (add (len $s) 3) }}{{ indent $sp ""}}{{wrap .Usage $cv}}{{end}}{{end}}{{end}}{{if .VisibleFlags}}
{{$s := join .Names ", "}}{{$s}}{{ $sp := subtract $cv (offset $s 3) }}{{ indent $sp ""}}{{wrap .Usage $cv}}{{end}}{{end}}{{end}}{{if .VisibleFlags}}
OPTIONS:
{{range .VisibleFlags}}{{.}}
Expand Down

0 comments on commit e01afb2

Please sign in to comment.