Add tests about additional help topics
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Eric Paris · committed by Eric Paris · parent f576d29 · Browse files · 2 files·+23 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+23 added−6 removed
- other:+23 added−6 removed
Provenance
- Commit
86a1686- Tree
d53e400- Author
Eric Paris <eparis@redhat.com>- Committer
Eric Paris <eparis@redhat.com>- Parent
f576d29
2 files changed+23 added−6 removed
modified:cobra_test.go+21 added-5 removed
69 unmodified lines70 rootcalled = true71 },72 }73 74+var cmdSubNoRun = &Command{75+ Use: "subnorun",76+ Short: "A subcommand without a Run function",77+ Long: "A long output about a subcommand without a Run function",78+}79+80 var cmdVersion1 = &Command{81 Use: "version",82 Short: "Print the version number",83 Long: `First version of the version command`,17 unmodified lines101 cmdTimes.ResetFlags()102 cmdRootNoRun.ResetFlags()103 cmdRootSameName.ResetFlags()104 cmdRootWithRun.ResetFlags()105+ cmdSubNoRun.ResetFlags()106 cmdRootNoRun.PersistentFlags().StringVarP(&flags2a, "strtwo", "t", "two", strtwoParentHelp)107 cmdEcho.Flags().IntVarP(&flagi1, "intone", "i", 123, "help message for flag intone")108 cmdTimes.Flags().IntVarP(&flagi2, "inttwo", "j", 234, "help message for flag inttwo")109 cmdPrint.Flags().IntVarP(&flagi3, "intthree", "i", 345, "help message for flag intthree")14 unmodified lines124 cmdTimes.ResetCommands()125 cmdRootNoRun.ResetCommands()126 cmdRootSameName.ResetCommands()127 cmdRootWithRun.ResetCommands()128+ cmdSubNoRun.ResetCommands()129 }130 131 func initialize() *Command {132 tt, tp, te = nil, nil, nil61 unmodified lines194 buf := new(bytes.Buffer)195 // Testing flag with invalid input196 c.SetOutput(buf)197 cmdEcho.AddCommand(cmdTimes)190- c.AddCommand(cmdPrint, cmdEcho)198+ c.AddCommand(cmdPrint, cmdEcho, cmdSubNoRun)199 c.SetArgs(strings.Split(input, " "))200 201 err := c.Execute()202 output := buf.String()292 unmodified lines495 }496 }497 498 func TestHelpCommand(t *testing.T) {491- c := fullSetupTest("help echo")492- checkResultContains(t, c, cmdEcho.Long)499+ x := fullSetupTest("help")500+ checkResultContains(t, x, cmdRootWithRun.Long)501 502+ x = fullSetupTest("help echo")503+ checkResultContains(t, x, cmdEcho.Long)504+494- r := fullSetupTest("help echo times")495- checkResultContains(t, r, cmdTimes.Long)505+ x = fullSetupTest("help echo times")506+ checkResultContains(t, x, cmdTimes.Long)507 }508 509 func TestChildCommandHelp(t *testing.T) {510 c := noRRSetupTest("print --help")1 unmodified line512 r := noRRSetupTest("echo times --help")513 checkResultContains(t, r, strtwoChildHelp)514 }515 516+func TestNonRunChildHelp(t *testing.T) {517+ x := noRRSetupTest("subnorun")518+ checkResultContains(t, x, cmdSubNoRun.Long)519+}520+521 func TestRunnableRootCommand(t *testing.T) {522 fullSetupTest("")523 524 if rootcalled != true {243 unmodified linesmodified:command.go+2 added-1 removed
232 unmodified lines233 {{ if .HasLocalFlags}}Flags:234 {{.LocalFlags.FlagUsages}}{{end}}235 {{ if .HasInheritedFlags}}Global Flags:236 {{.InheritedFlags.FlagUsages}}{{end}}{{if or (.HasHelpSubCommands) (.HasRunnableSiblings)}}237+Additional help topics:237-Additional help topics: {{if .HasHelpSubCommands}}{{range .Commands}}{{if not .Runnable}} {{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if .HasRunnableSiblings }}{{range .Parent.Commands}}{{if .Runnable}}{{if not (eq .Name $cmd.Name) }}238+{{if .HasHelpSubCommands}}{{range .Commands}}{{if not .Runnable}} {{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if .HasRunnableSiblings }}{{range .Parent.Commands}}{{if .Runnable}}{{if not (eq .Name $cmd.Name) }}239 {{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{end}}240 {{end}}{{ if .HasSubCommands }}241 Use "{{.Root.Name}} help [command]" for more information about a command.242 {{end}}`715 unmodified lines