From 15938366aef8ee4f32dff7bb358b38e1740be5e7 Mon Sep 17 00:00:00 2001 From: Matthew Johnson Date: Thu, 8 Feb 2018 09:42:06 -0800 Subject: [PATCH] Add -cover flag to go test Make go test (make check) report the coverage percentage of the unit tests that run. Add checkcoverage target to generate a coverage.out file for a given package. Signed-off-by: Matthew Johnson --- Makefile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6f9606e..44d7fe2 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,16 @@ install: gopath install -D -m 00644 yum.conf.in $(DESTDIR)/usr/share/defaults/mixer/yum.conf.in check: gopath - go test ${GO_PACKAGE_PREFIX}/... + go test -cover ${GO_PACKAGE_PREFIX}/... + +# TODO: when Go 1.10 comes out we will have support for passing multiple packages +# to coverprofile, so there will be no need to pass an individual package. +# At that time we can merge this target into check and run it against all +# packages every time. +checkcoverage: gopath + test ${PKG} + go test -cover ${GO_PACKAGE_PREFIX}/${PKG} -coverprofile=coverage.out + go tool cover -html=coverage.out .PHONY: lint lint: gopath