From ef2d047c454173cb2956531d8a45997edcf7fbb8 Mon Sep 17 00:00:00 2001 From: Irioth Date: Thu, 18 Jun 2020 09:34:54 +0300 Subject: [PATCH] added test for successfully used -v flag on command with subcommands --- command_test.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/command_test.go b/command_test.go index a3c3b84e9a..6add442865 100644 --- a/command_test.go +++ b/command_test.go @@ -389,7 +389,7 @@ func TestCommand_NoVersionFlagOnCommands(t *testing.T) { HideHelp: true, Action: func(c *Context) error { if len(c.App.VisibleFlags()) != 0 { - t.Fatalf("unexpected flag on command") + t.Fatal("unexpected flag on command") } return nil }, @@ -400,3 +400,25 @@ func TestCommand_NoVersionFlagOnCommands(t *testing.T) { err := app.Run([]string{"foo", "bar"}) expect(t, err, nil) } + +func TestCommand_CanAddVFlagOnCommands(t *testing.T) { + app := &App{ + Version: "some version", + Writer: ioutil.Discard, + Commands: []*Command{ + { + Name: "bar", + Usage: "this is for testing", + Subcommands: []*Command{{}}, // some subcommand + Flags: []Flag{ + &BoolFlag{ + Name: "v", + }, + }, + }, + }, + } + + err := app.Run([]string{"foo", "bar"}) + expect(t, err, nil) +}