Skip to content

Commit d2b631f

Browse files
committed
Add test for pull request #2258
Test fails with recent change and passes with 852060e
1 parent 98c6c1e commit d2b631f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

command_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5417,3 +5417,33 @@ func TestCommand_ParallelRun(t *testing.T) {
54175417
})
54185418
}
54195419
}
5420+
5421+
func TestCommand_FlagNameNoDefaultCommand(t *testing.T) {
5422+
var gotArgs Args
5423+
5424+
app := &Command{HideHelpCommand: true, HideHelp: true}
5425+
app.Commands = []*Command{&Command{
5426+
Name: "foo",
5427+
Flags: []Flag{
5428+
&BoolFlag{
5429+
Name: "list",
5430+
},
5431+
},
5432+
Action: func(ctx context.Context, c *Command) error {
5433+
gotArgs = c.Args()
5434+
return nil
5435+
},
5436+
}}
5437+
5438+
// flag has to be set to execute code path
5439+
app.Commands[0].Flags[0].Set("list", "true")
5440+
5441+
err := app.Run(context.Background(), []string{"list", "foo", "list"})
5442+
if err != nil {
5443+
t.Errorf("Unexpected error: got %v, want nil", err)
5444+
return
5445+
}
5446+
5447+
var wantArgs Args = &stringSliceArgs{v: []string{"list"}}
5448+
assert.Equal(t, wantArgs, gotArgs)
5449+
}

0 commit comments

Comments
 (0)