summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThcipriani <tcipriani@wikimedia.org>2018-08-02 21:16:35 +0000
committerGerrit Code Review <gerrit@wikimedia.org>2018-08-02 21:16:35 +0000
commit7b1c01c18b35f4294bd583a2cefced51872c4ce1 (patch)
treeabfbb9b9cab06e75c5ea2ef69e42784011ffdad9
parent1fe58ac948449ac79a78bca8655b034ddb98fe2b (diff)
parent44dc7d91313ee36aed1b85ae7f63c9e75ab78ff3 (diff)
downloadblubber-7b1c01c18b35f4294bd583a2cefced51872c4ce1.tar.gz
Merge "Provide Makefile rules for running linters and tests"
-rw-r--r--.gitignore1
-rw-r--r--CONTRIBUTING.md13
-rw-r--r--Makefile17
3 files changed, 26 insertions, 5 deletions
diff --git a/.gitignore b/.gitignore
index 483f344..e5224f2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
/.build
+/.lint-*
/bin
/blubber
/blubber.git
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 57d01c2..d9214a2 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -60,14 +60,17 @@ If you do update `Gopkg.toml` to add, update, or remove a dependency, simply
run `dep ensure && dep prune` after doing so, and commit the resulting
`vendor` directory changes.
-## Running tests
+## Running tests and linters
Tests and linters for packages/files you've changed will automatically run
-when you submit your changes to Gerrit for review. You can also run tests
-locally by running `go test`.
+when you submit your changes to Gerrit for review. You can also run them
+locally using the `Makefile`:
- go test ./... # for everything, or
- go test -run TestFuncName ./... # to run a single test
+ make lint # to run all linters
+ make unit # or all unit tests
+ make test # or all linters and unit tests
+
+ go test -run TestFuncName ./... # to run a single test function
## Getting your changes reviewed and merged
diff --git a/Makefile b/Makefile
index b4cab3f..0e94470 100644
--- a/Makefile
+++ b/Makefile
@@ -4,6 +4,9 @@ TARGETS ?= darwin/amd64 linux/amd64 linux/386 linux/arm linux/arm64 linux/ppc64l
PACKAGE := gerrit.wikimedia.org/r/blubber
REAL_CURDIR := $(shell readlink "$(CURDIR)" || echo "$(CURDIR)")
+GO_LIST_GOFILES := '{{range .GoFiles}}{{printf "%s/%s\n" $$.Dir .}}{{end}}{{range .XTestGoFiles}}{{printf "%s/%s\n" $$.Dir .}}{{end}}'
+GO_PACKAGES := $(shell go list ./...)
+
GO_LDFLAGS := \
-X $(PACKAGE)/meta.Version=$(shell cat VERSION) \
-X $(PACKAGE)/meta.GitCommit=$(shell git rev-parse --short HEAD)
@@ -21,4 +24,18 @@ release:
shasum -a 256 "$${f}" | awk '{print $$1}' > "$${f}.sha256"; \
done
+lint:
+ @echo > .lint-gofmt.diff
+ @go list -f $(GO_LIST_GOFILES) ./... | while read f; do \
+ gofmt -e -d "$${f}" >> .lint-gofmt.diff; \
+ done
+ @test ! -s .lint-gofmt.diff || (echo "gofmt found errors:"; cat .lint-gofmt.diff; exit 1)
+ golint -set_exit_status $(GO_PACKAGES)
+ go tool vet -composites=false $(GO_PACKAGES)
+
+unit:
+ go test -ldflags "$(GO_LDFLAGS)" $(GO_PACKAGES)
+
+test: unit lint
+
.PHONY: install release