Make test case more robust

This commit is contained in:
Naveen Gogineni 2022-08-24 21:20:43 -04:00 committed by Dan Buch
parent d89bc4a6e2
commit 96e41a628a
Signed by: meatballhat
GPG Key ID: A12F782281063434
3 changed files with 13 additions and 7 deletions

View File

@ -297,7 +297,6 @@ func printHelpCustom(out io.Writer, templ string, data interface{}, customFuncs
funcMap := template.FuncMap{ funcMap := template.FuncMap{
"join": strings.Join, "join": strings.Join,
"subtract": subtract, "subtract": subtract,
"add": add,
"indent": indent, "indent": indent,
"nindent": nindent, "nindent": nindent,
"trim": strings.TrimSpace, "trim": strings.TrimSpace,

View File

@ -907,6 +907,11 @@ App UsageText`,
Aliases: []string{"frb1", "frbb2", "frl2"}, 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", 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",
},
}, },
} }
@ -915,10 +920,12 @@ App UsageText`,
_ = app.Run([]string{"foo"}) _ = app.Run([]string{"foo"})
expected := `frobbly, frb1, frbb2, frl2 this is a long help output for the run command, long usage expected := "COMMANDS:\n" +
output, long usage output, long usage output, long usage output " frobbly, frb1, frbb2, frl2 this is a long help output for the run command, long usage \n" +
output, long usage output, long usage output` " 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) { if !strings.Contains(output.String(), expected) {
t.Errorf("expected output to include usage text; got: %q", output.String()) t.Errorf("expected output to include usage text; got: %q", output.String())
} }

View File

@ -22,7 +22,7 @@ AUTHOR{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}:
COMMANDS:{{range .VisibleCategories}}{{if .Name}} COMMANDS:{{range .VisibleCategories}}{{if .Name}}
{{.Name}}:{{range .VisibleCommands}} {{.Name}}:{{range .VisibleCommands}}
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{ $cv := offsetCommands .VisibleCommands 5}}{{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}} GLOBAL OPTIONS:{{range .VisibleFlagCategories}}
{{if .Name}}{{.Name}} {{if .Name}}{{.Name}}
@ -77,7 +77,7 @@ DESCRIPTION:
COMMANDS:{{range .VisibleCategories}}{{if .Name}} COMMANDS:{{range .VisibleCategories}}{{if .Name}}
{{.Name}}:{{range .VisibleCommands}} {{.Name}}:{{range .VisibleCommands}}
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{ $cv := offsetCommands .VisibleCommands 5}}{{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: OPTIONS:
{{range .VisibleFlags}}{{.}} {{range .VisibleFlags}}{{.}}