Skip to content

Commit ddafb58

Browse files
committed
test: add TestDefaultCommandWithShortFlagHandling for codecov
1 parent e23258a commit ddafb58

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

command_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5795,3 +5795,31 @@ func TestDefaultCommandWithShortFlag(t *testing.T) {
57955795
err := cmd.Run(buildTestContext(t), []string{"c", "-f", "baz"})
57965796
assert.NoError(t, err)
57975797
}
5798+
5799+
func TestDefaultCommandWithShortFlagHandling(t *testing.T) {
5800+
// Covers the shortOptionHandling for-loop path when DefaultCommand is set
5801+
cmd := &Command{
5802+
UseShortOptionHandling: true,
5803+
DefaultCommand: "run",
5804+
Commands: []*Command{
5805+
{
5806+
Name: "run",
5807+
Usage: "run the app",
5808+
Action: func(ctx context.Context, cmd *Command) error {
5809+
if cmd.String("foo") != "baz" {
5810+
return fmt.Errorf("expected foo=baz, got %s", cmd.String("foo"))
5811+
}
5812+
return nil
5813+
},
5814+
Flags: []Flag{
5815+
&StringFlag{
5816+
Name: "foo",
5817+
Aliases: []string{"f"},
5818+
},
5819+
},
5820+
},
5821+
},
5822+
}
5823+
err := cmd.Run(buildTestContext(t), []string{"c", "-f", "baz"})
5824+
assert.NoError(t, err)
5825+
}

0 commit comments

Comments
 (0)