From 58216320005c038f3b704c3e56fb8f53eb941ec3 Mon Sep 17 00:00:00 2001 From: Joshua Mervine Date: Tue, 17 Jun 2014 21:37:55 -0700 Subject: [PATCH 1/4] Adding VersionPrinter and tests. --- app_test.go | 22 +++++++++++++++++++++- help.go | 7 +++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app_test.go b/app_test.go index 0b9e154..51a2d4c 100644 --- a/app_test.go +++ b/app_test.go @@ -2,7 +2,7 @@ package cli_test import ( "fmt" - "github.com/codegangsta/cli" + "." "os" "testing" ) @@ -347,6 +347,26 @@ func TestAppHelpPrinter(t *testing.T) { } } +func TestAppVersionPrinter(t *testing.T) { + oldPrinter := cli.VersionPrinter + defer func() { + cli.VersionPrinter = oldPrinter + }() + + var wasCalled = false + cli.VersionPrinter = func(c *cli.Context) { + wasCalled = true + } + + app := cli.NewApp() + ctx := cli.NewContext(app, nil, nil) + cli.ShowVersion(ctx) + + if wasCalled == false { + t.Errorf("Version printer expected to be called, but was not") + } +} + func TestAppCommandNotFound(t *testing.T) { beforeRun, subcommandRun := false, false app := cli.NewApp() diff --git a/help.go b/help.go index 7c04005..45b9db8 100644 --- a/help.go +++ b/help.go @@ -92,6 +92,9 @@ var helpSubcommand = Command{ // Prints help for the App var HelpPrinter = printHelp +// Prints version for the App +var VersionPrinter = printVersion + func ShowAppHelp(c *Context) { HelpPrinter(AppHelpTemplate, c.App) } @@ -129,6 +132,10 @@ func ShowSubcommandHelp(c *Context) { // Prints the version number of the App func ShowVersion(c *Context) { + VersionPrinter(c) +} + +func printVersion(c *Context) { fmt.Printf("%v version %v\n", c.App.Name, c.App.Version) } From 7ca86444e8a8c42f1a87d6fa093d6f9fc5d50230 Mon Sep 17 00:00:00 2001 From: Josh Mervine Date: Tue, 17 Jun 2014 22:28:33 -0700 Subject: [PATCH 2/4] making all pathing for cli local in tests for easier fork testing --- cli_test.go | 2 +- command_test.go | 2 +- context_test.go | 2 +- flag_test.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cli_test.go b/cli_test.go index 30f3c13..ec800f7 100644 --- a/cli_test.go +++ b/cli_test.go @@ -1,7 +1,7 @@ package cli_test import ( - "github.com/codegangsta/cli" + "." "os" ) diff --git a/command_test.go b/command_test.go index 3afd83e..7c94322 100644 --- a/command_test.go +++ b/command_test.go @@ -2,7 +2,7 @@ package cli_test import ( "flag" - "github.com/codegangsta/cli" + "." "testing" ) diff --git a/context_test.go b/context_test.go index 89041b9..25b543c 100644 --- a/context_test.go +++ b/context_test.go @@ -2,7 +2,7 @@ package cli_test import ( "flag" - "github.com/codegangsta/cli" + "." "testing" ) diff --git a/flag_test.go b/flag_test.go index 1c05f01..8a98f99 100644 --- a/flag_test.go +++ b/flag_test.go @@ -1,7 +1,7 @@ package cli_test import ( - "github.com/codegangsta/cli" + "." "fmt" "reflect" From 8f55ca83ff0e27563fbd54fb51e845f97fc8162d Mon Sep 17 00:00:00 2001 From: Josh Mervine Date: Tue, 17 Jun 2014 22:33:30 -0700 Subject: [PATCH 3/4] running go fmt --- app_test.go | 8 ++++---- command_test.go | 24 ++++++++++++------------ context_test.go | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/app_test.go b/app_test.go index 51a2d4c..fe5a78e 100644 --- a/app_test.go +++ b/app_test.go @@ -1,8 +1,8 @@ package cli_test import ( - "fmt" "." + "fmt" "os" "testing" ) @@ -348,7 +348,7 @@ func TestAppHelpPrinter(t *testing.T) { } func TestAppVersionPrinter(t *testing.T) { - oldPrinter := cli.VersionPrinter + oldPrinter := cli.VersionPrinter defer func() { cli.VersionPrinter = oldPrinter }() @@ -359,8 +359,8 @@ func TestAppVersionPrinter(t *testing.T) { } app := cli.NewApp() - ctx := cli.NewContext(app, nil, nil) - cli.ShowVersion(ctx) + ctx := cli.NewContext(app, nil, nil) + cli.ShowVersion(ctx) if wasCalled == false { t.Errorf("Version printer expected to be called, but was not") diff --git a/command_test.go b/command_test.go index 7c94322..e601fc1 100644 --- a/command_test.go +++ b/command_test.go @@ -1,8 +1,8 @@ package cli_test import ( - "flag" "." + "flag" "testing" ) @@ -14,12 +14,12 @@ func TestCommandDoNotIgnoreFlags(t *testing.T) { c := cli.NewContext(app, set, set) - command := cli.Command { - Name: "test-cmd", - ShortName: "tc", - Usage: "this is for testing", + command := cli.Command{ + Name: "test-cmd", + ShortName: "tc", + Usage: "this is for testing", Description: "testing", - Action: func(_ *cli.Context) { }, + Action: func(_ *cli.Context) {}, } err := command.Run(c) @@ -34,12 +34,12 @@ func TestCommandIgnoreFlags(t *testing.T) { c := cli.NewContext(app, set, set) - command := cli.Command { - Name: "test-cmd", - ShortName: "tc", - Usage: "this is for testing", - Description: "testing", - Action: func(_ *cli.Context) { }, + command := cli.Command{ + Name: "test-cmd", + ShortName: "tc", + Usage: "this is for testing", + Description: "testing", + Action: func(_ *cli.Context) {}, SkipFlagParsing: true, } err := command.Run(c) diff --git a/context_test.go b/context_test.go index 25b543c..7c6c8b9 100644 --- a/context_test.go +++ b/context_test.go @@ -1,8 +1,8 @@ package cli_test import ( - "flag" "." + "flag" "testing" ) From 089def51d86d5f09b1153d01976cd976bbf8822d Mon Sep 17 00:00:00 2001 From: Josh Mervine Date: Mon, 4 Aug 2014 11:30:13 -0700 Subject: [PATCH 4/4] Tweaking tests, removing local import. --- app_test.go | 1 - command_test.go | 3 ++- context_test.go | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app_test.go b/app_test.go index 32807bf..81d1174 100644 --- a/app_test.go +++ b/app_test.go @@ -1,7 +1,6 @@ package cli_test import ( - "." "fmt" "os" "testing" diff --git a/command_test.go b/command_test.go index e601fc1..c0f556a 100644 --- a/command_test.go +++ b/command_test.go @@ -1,9 +1,10 @@ package cli_test import ( - "." "flag" "testing" + + "github.com/codegangsta/cli" ) func TestCommandDoNotIgnoreFlags(t *testing.T) { diff --git a/context_test.go b/context_test.go index 70bf2ad..b2d2412 100644 --- a/context_test.go +++ b/context_test.go @@ -1,7 +1,6 @@ package cli_test import ( - "." "flag" "testing" "time"