MCPcopy
hub / github.com/urfave/cli / TestCommand_Run_CommandWithSubcommandHasHelpTopic

Function TestCommand_Run_CommandWithSubcommandHasHelpTopic

command_test.go:2556–2599  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2554}
2555
2556func TestCommand_Run_CommandWithSubcommandHasHelpTopic(t *testing.T) {
2557 subcommandHelpTopics := [][]string{
2558 {"foo", "--help"},
2559 {"foo", "-h"},
2560 {"foo", "help"},
2561 }
2562
2563 for _, flagSet := range subcommandHelpTopics {
2564 t.Run(fmt.Sprintf("checking with flags %v", flagSet), func(t *testing.T) {
2565 buf := new(bytes.Buffer)
2566
2567 subCmdBar := &Command{
2568 Name: "bar",
2569 Usage: "does bar things",
2570 }
2571 subCmdBaz := &Command{
2572 Name: "baz",
2573 Usage: "does baz things",
2574 }
2575 cmd := &Command{
2576 Name: "foo",
2577 Description: "descriptive wall of text about how it does foo things",
2578 Commands: []*Command{subCmdBar, subCmdBaz},
2579 Action: func(context.Context, *Command) error { return nil },
2580 Writer: buf,
2581 }
2582
2583 err := cmd.Run(buildTestContext(t), flagSet)
2584 assert.NoError(t, err)
2585
2586 output := buf.String()
2587
2588 assert.NotContains(t, output, "No help topic for", "expect a help topic, got none")
2589
2590 for _, shouldContain := range []string{
2591 cmd.Name, cmd.Description,
2592 subCmdBar.Name, subCmdBar.Usage,
2593 subCmdBaz.Name, subCmdBaz.Usage,
2594 } {
2595 assert.Contains(t, output, shouldContain, "want help to contain %q, did not: \n%q", shouldContain, output)
2596 }
2597 })
2598 }
2599}
2600
2601func TestCommand_Run_SubcommandFullPath(t *testing.T) {
2602 out := &bytes.Buffer{}

Callers

nothing calls this directly

Calls 3

RunMethod · 0.95
buildTestContextFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected