Merge pull request #88 from eparis/subhelptest
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Add tests about additional help topics
authored by Eric Paris · committed by Eric Paris · parents aab4e37, 86a1686 · 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
b78326b- Tree
ad05da3- Author
Eric Paris <eparis@redhat.com>- Committer
Eric Paris <eparis@redhat.com>- Parent 1
aab4e37- Parent 2
86a1686
2 files changed+23 added−6 removed
modified:cobra_test.go+21 added-5 removed
70 unmodified lines71 rootcalled = true72 },73 }74 75+var cmdSubNoRun = &Command{76+ Use: "subnorun",77+ Short: "A subcommand without a Run function",78+ Long: "A long output about a subcommand without a Run function",79+}80+81 var cmdVersion1 = &Command{82 Use: "version",83 Short: "Print the version number",84 Long: `First version of the version command`,17 unmodified lines102 cmdTimes.ResetFlags()103 cmdRootNoRun.ResetFlags()104 cmdRootSameName.ResetFlags()105 cmdRootWithRun.ResetFlags()106+ cmdSubNoRun.ResetFlags()107 cmdRootNoRun.PersistentFlags().StringVarP(&flags2a, "strtwo", "t", "two", strtwoParentHelp)108 cmdEcho.Flags().IntVarP(&flagi1, "intone", "i", 123, "help message for flag intone")109 cmdTimes.Flags().IntVarP(&flagi2, "inttwo", "j", 234, "help message for flag inttwo")110 cmdPrint.Flags().IntVarP(&flagi3, "intthree", "i", 345, "help message for flag intthree")14 unmodified lines125 cmdTimes.ResetCommands()126 cmdRootNoRun.ResetCommands()127 cmdRootSameName.ResetCommands()128 cmdRootWithRun.ResetCommands()129+ cmdSubNoRun.ResetCommands()130 }131 132 func initialize() *Command {133 tt, tp, te = nil, nil, nil61 unmodified lines195 buf := new(bytes.Buffer)196 // Testing flag with invalid input197 c.SetOutput(buf)198 cmdEcho.AddCommand(cmdTimes)191- c.AddCommand(cmdPrint, cmdEcho)199+ c.AddCommand(cmdPrint, cmdEcho, cmdSubNoRun)200 c.SetArgs(strings.Split(input, " "))201 202 err := c.Execute()203 output := buf.String()303 unmodified lines507 }508 }509 510 func TestHelpCommand(t *testing.T) {503- c := fullSetupTest("help echo")504- checkResultContains(t, c, cmdEcho.Long)511+ x := fullSetupTest("help")512+ checkResultContains(t, x, cmdRootWithRun.Long)513 514+ x = fullSetupTest("help echo")515+ checkResultContains(t, x, cmdEcho.Long)516+506- r := fullSetupTest("help echo times")507- checkResultContains(t, r, cmdTimes.Long)517+ x = fullSetupTest("help echo times")518+ checkResultContains(t, x, cmdTimes.Long)519 }520 521 func TestChildCommandHelp(t *testing.T) {522 c := noRRSetupTest("print --help")1 unmodified line524 r := noRRSetupTest("echo times --help")525 checkResultContains(t, r, strtwoChildHelp)526 }527 528+func TestNonRunChildHelp(t *testing.T) {529+ x := noRRSetupTest("subnorun")530+ checkResultContains(t, x, cmdSubNoRun.Long)531+}532+533 func TestRunnableRootCommand(t *testing.T) {534 fullSetupTest("")535 536 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