From 79933615f7988cb731baa0768a45b39008f18b20 Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Fri, 7 Jul 2017 11:30:47 +0200 Subject: add first test --- Makefile | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index cc2c7ca..c1e786e 100644 --- a/Makefile +++ b/Makefile @@ -11,13 +11,40 @@ GO_LDFLAGS = -s -w build/gofu: FORCE $(GO) install $(GO_BUILDFLAGS) -ldflags '$(GO_LDFLAGS)' '$(PKG)' -build/%: +$(addprefix build/,$(APPLETS)): ln -s gofu $@ install: FORCE all install -D -m 0755 build/gofu "$(DESTDIR)$(PREFIX)/bin/gofu" for APPLET in $(APPLETS); do ln -s gofu "$(DESTDIR)$(PREFIX)/bin/$${APPLET}"; done +# which packages to test with static checkers? +GO_ALLPKGS := $(PKG) $(shell go list $(PKG)/pkg/...) +# which packages to test with `go test`? +GO_TESTPKGS := $(shell go list -f '{{if .TestGoFiles}}{{.ImportPath}}{{end}}' $(PKG)/pkg/...) +# which packages to measure coverage for? +GO_COVERPKGS := $(shell go list $(PKG)/pkg/...) +# output files from `go test` +GO_COVERFILES := $(patsubst %,build/%.cover.out,$(subst /,_,$(GO_TESTPKGS))) + +# down below, I need to substitute spaces with commas; because of the syntax, +# I have to get these separators from variables +space := $(null) $(null) +comma := , + +check: all static-check build/cover.html FORCE + @echo -e "\e[1;32m>> All tests successful.\e[0m" +static-check: FORCE + @if s="$$(gofmt -s -l *.go pkg 2>/dev/null)" && test -n "$$s"; then printf ' => %s\n%s\n' gofmt "$$s"; false; fi + @if s="$$(golint . && find pkg -type d -exec golint {} \; 2>/dev/null)" && test -n "$$s"; then printf ' => %s\n%s\n' golint "$$s"; false; fi + $(GO) vet $(GO_ALLPKGS) +build/%.cover.out: FORCE + $(GO) test $(GO_BUILDFLAGS) -ldflags '$(GO_LDFLAGS)' -coverprofile=$@ -covermode=count -coverpkg=$(subst $(space),$(comma),$(GO_COVERPKGS)) $(subst _,/,$*) +build/cover.out: $(GO_COVERFILES) + util/gocovcat.go $(GO_COVERFILES) > $@ +build/cover.html: build/cover.out + $(GO) tool cover -html $< -o $@ + vendor: FORCE golangvend -- cgit v1.3.1