summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Duvall <dduvall@wikimedia.org>2018-07-31 16:43:05 -0700
committerDan Duvall <dduvall@wikimedia.org>2018-08-01 10:05:08 -0700
commit44dc7d91313ee36aed1b85ae7f63c9e75ab78ff3 (patch)
treefa2a0c8fd0850a5d9ad91c6ae860d8cfd43ee4a1
parent80936122c749199bb9a376a23ae85e45c4abebe0 (diff)
downloadblubber-44dc7d91313ee36aed1b85ae7f63c9e75ab78ff3.tar.gz
Provide Makefile rules for running linters and tests
With the move to Gerrit and away from Phabricator/Arcanist, we lost an easy way to run linters. New rules have been added to the `Makefile`, `lint`, `unit`, and `test` that run linters, unit tests, and both linters and unit tests, respectively. Bug: T200452 Change-Id: I0742daaa14389841d88f13eba47dee07ac127cf2
-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