From b83af8d38ca294154d3eb39a62dc62f786b003b6 Mon Sep 17 00:00:00 2001 From: Oliver Tonnhofer Date: Tue, 6 Dec 2016 16:17:30 +0100 Subject: [PATCH] add test-coverage --- Makefile | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Makefile b/Makefile index 8262052..bee2fb4 100644 --- a/Makefile +++ b/Makefile @@ -62,3 +62,25 @@ build-license-deps: | fold -s -w 80 \ >> LICENSE.deps \ ' _ {} \; + + + +comma:= , +empty:= +space:= $(empty) $(empty) +COVER_IGNORE:='/vendor|/cmd' +COVER_PACKAGES:= $(shell $(GO) list ./... | grep -Ev $(COVER_IGNORE)) +COVER_PACKAGES_LIST:=$(subst $(space),$(comma),$(COVER_PACKAGES)) + +test-coverage: + mkdir -p .coverprofile + rm -f .coverprofile/* + $(GO) list -f '{{if gt (len .TestGoFiles) 0}}"$(GO) test -covermode count -coverprofile ./.coverprofile/{{.Name}}-$$$$.coverprofile -coverpkg $(COVER_PACKAGES_LIST) {{.ImportPath}}"{{end}}' ./... \ + | grep -Ev $(COVER_IGNORE) \ + | xargs -n 1 bash -c + $(GOPATH)/bin/gocovmerge .coverprofile/*.coverprofile > overalls.coverprofile + rm -rf .coverprofile + +test-coverage-html: test-coverage + $(GO) tool cover -html overalls.coverprofile +