From a38f7761ce1e5345e62370eeecd7ab3e5aee0c76 Mon Sep 17 00:00:00 2001 From: Lai-YT <381xvmvbib@gmail.com> Date: Fri, 29 Mar 2024 20:44:47 +0800 Subject: [PATCH] Exclude mock files from test coverage --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index dbf3a9b..5806f0c 100644 --- a/Makefile +++ b/Makefile @@ -5,15 +5,16 @@ PACKAGES ?= $(shell $(GO) list ./...) GOFILES := $(shell find . -name "*.go") TESTTAGS ?= "-test.shuffle=on" COVERPROFILE ?= coverage.out +COVEREXCLUDE ?= "mock" .PHONY: test test: $(GO) test $(TESTTAGS) -v $(PACKAGES) -# TODO: Exclude mock files from coverage. .PHONY: test-coverage test-coverage: - $(GO) test $(TESTTAGS) -v $(PACKAGES) -coverprofile=$(COVERPROFILE) + $(GO) test $(TESTTAGS) -v $(PACKAGES) -coverprofile=/tmp/$(COVERPROFILE) + cat /tmp/$(COVERPROFILE) | grep -v -E $(COVEREXCLUDE) > $(COVERPROFILE) $(GO) tool cover -func=$(COVERPROFILE) .PHONY: fmt