From 44371a2ac6c3bf1372ca23ff24d16038590c6c7c Mon Sep 17 00:00:00 2001 From: Irioth Date: Thu, 18 Jun 2020 00:46:15 +0300 Subject: [PATCH] test for version flag on commands --- command_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/command_test.go b/command_test.go index 765081e..c1d106d 100644 --- a/command_test.go +++ b/command_test.go @@ -377,3 +377,27 @@ func TestCommand_Run_CustomShellCompleteAcceptsMalformedFlags(t *testing.T) { } } + +func TestCommand_NoVersionFlagOnCommands(t *testing.T) { + app := &App{ + Version: "some version", + Commands: []*Command{ + { + Name: "bar", + Usage: "this is for testing", + Subcommands: []*Command{{}}, // some subcommand + Action: func(c *Context) error { + for _, f := range c.App.VisibleFlags() { + if f == VersionFlag { + t.Fatalf("unexpected version flag") + } + } + return nil + }, + }, + }, + } + + err := app.Run([]string{"foo", "bar"}) + expect(t, err, nil) +}