@@ -5848,13 +5848,15 @@ func TestDefaultCommandWithSubcommandFlags(t *testing.T) {
58485848
58495849func 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
58775880func 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