Skip to content

Commit 9473f04

Browse files
committed
test: add actionRun guard to short flag tests per review feedback
1 parent 7cbecbe commit 9473f04

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

command_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5848,13 +5848,15 @@ func TestDefaultCommandWithSubcommandFlags(t *testing.T) {
58485848

58495849
func TestDefaultCommandWithShortFlag(t *testing.T) {
58505850
// Covers the short-flag splitting path in parseFlags when DefaultCommand is set
5851+
actionRun := false
58515852
cmd := &Command{
58525853
DefaultCommand: "run",
58535854
Commands: []*Command{
58545855
{
58555856
Name: "run",
58565857
Usage: "run the app",
58575858
Action: func(ctx context.Context, cmd *Command) error {
5859+
actionRun = true
58585860
if cmd.String("foo") != "baz" {
58595861
return fmt.Errorf("expected foo=baz, got %s", cmd.String("foo"))
58605862
}
@@ -5872,10 +5874,12 @@ func TestDefaultCommandWithShortFlag(t *testing.T) {
58725874

58735875
err := cmd.Run(buildTestContext(t), []string{"c", "-f", "baz"})
58745876
assert.NoError(t, err)
5877+
assert.True(t, actionRun, "expected run action to be executed")
58755878
}
58765879

58775880
func TestDefaultCommandWithShortFlagHandling(t *testing.T) {
58785881
// Covers the shortOptionHandling for-loop path when DefaultCommand is set
5882+
actionRun := false
58795883
cmd := &Command{
58805884
UseShortOptionHandling: true,
58815885
DefaultCommand: "run",
@@ -5884,6 +5888,7 @@ func TestDefaultCommandWithShortFlagHandling(t *testing.T) {
58845888
Name: "run",
58855889
Usage: "run the app",
58865890
Action: func(ctx context.Context, cmd *Command) error {
5891+
actionRun = true
58875892
if cmd.String("foo") != "baz" {
58885893
return fmt.Errorf("expected foo=baz, got %s", cmd.String("foo"))
58895894
}
@@ -5900,4 +5905,5 @@ func TestDefaultCommandWithShortFlagHandling(t *testing.T) {
59005905
}
59015906
err := cmd.Run(buildTestContext(t), []string{"c", "-f", "baz"})
59025907
assert.NoError(t, err)
5908+
assert.True(t, actionRun, "expected run action to be executed")
59035909
}

0 commit comments

Comments
 (0)