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

Function TestCommand_Walk_ShortCircuit

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

Source from the content-addressed store, hash-verified

6405}
6406
6407func TestCommand_Walk_ShortCircuit(t *testing.T) {
6408 subCmd := &Command{Name: "bar"}
6409 subSubCmd := &Command{Name: "baz"}
6410 subCmd.Commands = []*Command{subSubCmd}
6411
6412 cmd := &Command{
6413 Name: "foo",
6414 Commands: []*Command{subCmd},
6415 }
6416
6417 errWalk := fmt.Errorf("stop")
6418 var visited []string
6419 err := cmd.Walk(func(c *Command) error {
6420 visited = append(visited, c.Name)
6421 if c.Name == "bar" {
6422 return errWalk
6423 }
6424 return nil
6425 })
6426 assert.ErrorIs(t, err, errWalk)
6427 assert.Equal(t, []string{"foo", "bar"}, visited)
6428}
6429
6430func TestCommand_Walk_Hidden(t *testing.T) {
6431 subCmd := &Command{Name: "bar", HideHelp: true}

Callers

nothing calls this directly

Calls 1

WalkMethod · 0.95

Tested by

no test coverage detected