diff options
author | Jacob Vosmaer (GitLab) <jacob@gitlab.com> | 2017-01-05 13:58:26 +0300 |
---|---|---|
committer | Jacob Vosmaer (GitLab) <jacob@gitlab.com> | 2017-01-05 13:58:26 +0300 |
commit | 7f85b73b414127fe7ca2afc1f729631b8c51c23f (patch) | |
tree | f7c6021feb03fc04c129cd8f541d7cc091e51bf8 | |
parent | e3f1dceaf68c4322928a8ac3216c9a6dc98eca4b (diff) | |
parent | d625fbb04676f4a8d7d7d5e7219fd73f3fe3044a (diff) |
Merge branch 'gofmt' into 'master'
All code must pass "gofmt -s"
See merge request !34
-rw-r--r-- | Makefile | 6 | ||||
-rwxr-xr-x | _support/gofmt-all | 27 | ||||
-rw-r--r-- | helper/logging_test.go | 20 |
3 files changed, 42 insertions, 11 deletions
@@ -19,9 +19,13 @@ build: ${BUILD_DIR}/_build $(shell find . -name '*.go' -not -path './vendor/*') cd ${PKG_BUILD_DIR} && $(foreach cmd,${CMDS},go build ./cmd/${cmd} && ) true mv $(foreach cmd,${CMDS},${PKG_BUILD_DIR}/${cmd}) ${BUILD_DIR}/ -test: ${BUILD_DIR}/_build +test: ${BUILD_DIR}/_build fmt cd ${PKG_BUILD_DIR} && go test ./... +.PHONY: fmt +fmt: + _support/gofmt-all -n | awk '{ print } END { if (NR > 0) { print "Please run _support/gofmt-all -f"; exit 1 } }' + clean: rm -rf ${BUILD_DIR}/_build rm -rf client/testdata diff --git a/_support/gofmt-all b/_support/gofmt-all new file mode 100755 index 000000000..e8d80f892 --- /dev/null +++ b/_support/gofmt-all @@ -0,0 +1,27 @@ +#!/bin/sh +set -e + +if [ $# -ne 1 ] ; then + echo "Usage: $0 [ -n | -f ]" + echo + echo "$0 runs 'gofmt -s' on all non-vendored .go files in this project." + echo " -n List files that would be changed" + echo " -f Apply changes" + exit 1 +fi + +gofmt='gofmt -s -l' +case "x$1" in +x-n) + # Command is already as it should be. + ;; +x-f) + gofmt="${gofmt} -w" + ;; +*) + echo "Invalid argument: $1" + exit 1 + ;; +esac + +${gofmt} $(find . -name '*.go' -not -path './vendor/*' -not -path './_*') diff --git a/helper/logging_test.go b/helper/logging_test.go index c51bf9ea7..f116784ca 100644 --- a/helper/logging_test.go +++ b/helper/logging_test.go @@ -5,15 +5,15 @@ import ( ) func TestParsingCommandSuccessfully(t *testing.T) { - cases := make(map[string][]string) - cases["foo"] = []string{"--long-arg", "path/arg", "-f", "foo", "arg1", "arg2"} - cases["bar"] = []string{"bar", "-d", "arg1", "arg2"} - cases["baz"] = []string{"baz", "-f=\"some_value\""} + cases := make(map[string][]string) + cases["foo"] = []string{"--long-arg", "path/arg", "-f", "foo", "arg1", "arg2"} + cases["bar"] = []string{"bar", "-d", "arg1", "arg2"} + cases["baz"] = []string{"baz", "-f=\"some_value\""} - for k,v := range cases { - subCmd := ExtractSubcommand(v) - if k != subCmd { - t.Error("Expected subcommand for", v, "to be", k, ", got", subCmd) - } - } + for k, v := range cases { + subCmd := ExtractSubcommand(v) + if k != subCmd { + t.Error("Expected subcommand for", v, "to be", k, ", got", subCmd) + } + } } |