From d1371ecdb41640e57208c5ed5e4b0f5249b4364d Mon Sep 17 00:00:00 2001 From: Chris Broadfoot Date: Sat, 20 Aug 2016 00:09:46 -0700 Subject: [PATCH] gofmt, govet, run those in Travis, add 1.7 --- .travis.yml | 18 +++++++++++++----- bash_completions_test.go | 2 +- cobra_test.go | 5 ++--- command_test.go | 8 ++++---- doc/man_docs.go | 2 +- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6e84be54..b729bcb7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,13 @@ language: go -go: - - 1.4.3 - - 1.5.4 - - 1.6.3 - - tip + +matrix: + include: + - go: 1.4.3 + env: NOVET=true # No bundled vet. + - go: 1.5.4 + - go: 1.6.3 + - go: 1.7 + - go: tip matrix: allow_failures: @@ -16,3 +20,7 @@ before_install: script: - PATH=$PATH:$PWD/bin go test -v ./... - go build + - diff -u <(echo -n) <(gofmt -d -s .) + - if [ -z $NOVET ]; then + diff -u <(echo -n) <(go tool vet . 2>&1 | grep -vE 'ExampleCommand|bash_completions.*Fprint'); + fi diff --git a/bash_completions_test.go b/bash_completions_test.go index 5f4cb4d1..185570b2 100644 --- a/bash_completions_test.go +++ b/bash_completions_test.go @@ -155,7 +155,7 @@ func TestBashCompletionHiddenFlag(t *testing.T) { cmdTrue.GenBashCompletion(out) bashCompletion := out.String() if strings.Contains(bashCompletion, flagName) { - t.Error("expected completion to not include %q flag: Got %v", flagName, bashCompletion) + t.Errorf("expected completion to not include %q flag: Got %v", flagName, bashCompletion) } } diff --git a/cobra_test.go b/cobra_test.go index f23da7b8..699a2f63 100644 --- a/cobra_test.go +++ b/cobra_test.go @@ -916,15 +916,14 @@ func TestRootUnknownCommand(t *testing.T) { func TestRootUnknownCommandSilenced(t *testing.T) { r := noRRSetupTestSilenced("bogus") - s := "Run 'cobra-test --help' for usage.\n" if r.Output != "" { - t.Errorf("Unexpected response.\nExpecting to be:\n %q\nGot:\n %q\n", s, r.Output) + t.Errorf("Unexpected response.\nExpecting to be: \n\"\"\n Got:\n %q\n", r.Output) } r = noRRSetupTestSilenced("--strtwo=a bogus") if r.Output != "" { - t.Errorf("Unexpected response.\nExpecting to be:\n %q\nGot:\n %q\n", s, r.Output) + t.Errorf("Unexpected response.\nExpecting to be:\n\"\"\nGot:\n %q\n", r.Output) } } diff --git a/command_test.go b/command_test.go index 127ca0e6..b0c17e29 100644 --- a/command_test.go +++ b/command_test.go @@ -142,11 +142,11 @@ func TestCommandsAreSorted(t *testing.T) { var tmpCommand = &Command{Use: "tmp"} - for _, name := range(originalNames) { + for _, name := range originalNames { tmpCommand.AddCommand(&Command{Use: name}) } - for i, c := range(tmpCommand.Commands()) { + for i, c := range tmpCommand.Commands() { if expectedNames[i] != c.Name() { t.Errorf("expected: %s, got: %s", expectedNames[i], c.Name()) } @@ -162,11 +162,11 @@ func TestEnableCommandSortingIsDisabled(t *testing.T) { var tmpCommand = &Command{Use: "tmp"} - for _, name := range(originalNames) { + for _, name := range originalNames { tmpCommand.AddCommand(&Command{Use: name}) } - for i, c := range(tmpCommand.Commands()) { + for i, c := range tmpCommand.Commands() { if originalNames[i] != c.Name() { t.Errorf("expected: %s, got: %s", originalNames[i], c.Name()) } diff --git a/doc/man_docs.go b/doc/man_docs.go index b202029d..5798d0fb 100644 --- a/doc/man_docs.go +++ b/doc/man_docs.go @@ -66,7 +66,7 @@ func GenManTreeFromOpts(cmd *cobra.Command, opts GenManTreeOptions) error { separator = opts.CommandSeparator } basename := strings.Replace(cmd.CommandPath(), " ", separator, -1) - filename := filepath.Join(opts.Path, basename + "." + section) + filename := filepath.Join(opts.Path, basename+"."+section) f, err := os.Create(filename) if err != nil { return err