From 76357374879c3e4080a9c1fd53c98ab0c689c970 Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Mon, 12 Jun 2017 15:20:24 -0500 Subject: [PATCH] Add coverage tools to Makefile `make cover-viz` will now generate an HTML coverage report for the entire codebase. --- Makefile | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a5113c2ab..6ef21fda0 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: glide vendor-update docker pilosa crossbuild install generate statik release test +.PHONY: glide vendor-update docker pilosa crossbuild install generate statik release test cover cover-pkg cover-viz GLIDE := $(shell command -v glide 2>/dev/null) STATIK := $(shell command -v statik 2>/dev/null) @@ -6,6 +6,7 @@ PROTOC := $(shell command -v protoc 2>/dev/null) VERSION := $(shell git describe --tags 2> /dev/null || echo unknown) IDENTIFIER := $(VERSION)-$(GOOS)-$(GOARCH) CLONE_URL=github.com/pilosa/pilosa +PKGS := $(shell cd $(GOPATH)/src/$(CLONE_URL); go list ./... | grep -v vendor) BUILD_TIME=`date -u +%FT%T%z` LDFLAGS="-X github.com/pilosa/pilosa.Version=$(VERSION) -X github.com/pilosa/pilosa.BuildTime=$(BUILD_TIME)" @@ -34,7 +35,23 @@ glide.lock: glide glide.yaml vendor-update: glide.lock test: vendor - go test $(shell cd $(GOPATH)/src/$(CLONE_URL); go list ./... | grep -v vendor) $(TESTFLAGS) + go test $(PKGS) $(TESTFLAGS) + +cover: vendor + mkdir -p build/coverage + echo "mode: set" > build/coverage/all.out + for pkg in $(PKGS) ; do \ + make cover-pkg PKG=$$pkg ; \ + done + +cover-pkg: + mkdir -p build/coverage + touch build/coverage/$(subst /,-,$(PKG)).out + go test -coverprofile=build/coverage/$(subst /,-,$(PKG)).out $(PKG) + tail +2 build/coverage/$(subst /,-,$(PKG)).out >> build/coverage/all.out + +cover-viz: cover + go tool cover -html=build/coverage/all.out pilosa: vendor go build -ldflags $(LDFLAGS) $(FLAGS) $(CLONE_URL)/cmd/pilosa