From 9792d442bbd5b6a0f5e0644221644d822ba0877d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A9=E5=85=83?= Date: Fri, 6 Nov 2020 17:07:34 +0800 Subject: [PATCH 1/3] make go covermod configurable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 天元 --- makelib/golang.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/makelib/golang.mk b/makelib/golang.mk index 989a36d..d338d83 100644 --- a/makelib/golang.mk +++ b/makelib/golang.mk @@ -129,6 +129,7 @@ endif GO_COMMON_FLAGS = $(GO_BUILDFLAGS) -tags '$(GO_TAGS)' GO_STATIC_FLAGS = $(GO_COMMON_FLAGS) $(GO_PKG_STATIC_FLAGS) -installsuffix static -ldflags '$(GO_LDFLAGS)' GO_GENERATE_FLAGS = $(GO_BUILDFLAGS) -tags 'generate $(GO_TAGS)' +GO_COVER_MODE ?= count export GO111MODULE @@ -171,7 +172,7 @@ ifeq ($(GO_NOCOV),true) else @mkdir -p $(GO_TEST_OUTPUT) @CGO_ENABLED=0 $(GOHOST) test -i -cover $(GO_STATIC_FLAGS) $(GO_PACKAGES) || $(FAIL) - @CGO_ENABLED=0 $(GOHOST) test -v -covermode=count -coverprofile=$(GO_TEST_OUTPUT)/coverage.txt $(GO_TEST_FLAGS) $(GO_STATIC_FLAGS) $(GO_PACKAGES) 2>&1 | tee $(GO_TEST_OUTPUT)/unit-tests.log || $(FAIL) + @CGO_ENABLED=0 $(GOHOST) test -v -covermode=$(GO_COVER_MODE) -coverprofile=$(GO_TEST_OUTPUT)/coverage.txt $(GO_TEST_FLAGS) $(GO_STATIC_FLAGS) $(GO_PACKAGES) 2>&1 | tee $(GO_TEST_OUTPUT)/unit-tests.log || $(FAIL) @cat $(GO_TEST_OUTPUT)/unit-tests.log | $(GOJUNIT) -set-exit-code > $(GO_TEST_OUTPUT)/unit-tests.xml || $(FAIL) @$(GOCOVER_COBERTURA) < $(GO_TEST_OUTPUT)/coverage.txt > $(GO_TEST_OUTPUT)/coverage.xml endif From d1362169c11e9b7ab2608c2488d65812ec6e68c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A9=E5=85=83?= Date: Tue, 10 Nov 2020 16:12:06 +0800 Subject: [PATCH 2/3] run go test -race need to make CGO_ENABLED=1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 天元 --- makelib/golang.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/makelib/golang.mk b/makelib/golang.mk index d338d83..ff9549f 100644 --- a/makelib/golang.mk +++ b/makelib/golang.mk @@ -130,6 +130,7 @@ GO_COMMON_FLAGS = $(GO_BUILDFLAGS) -tags '$(GO_TAGS)' GO_STATIC_FLAGS = $(GO_COMMON_FLAGS) $(GO_PKG_STATIC_FLAGS) -installsuffix static -ldflags '$(GO_LDFLAGS)' GO_GENERATE_FLAGS = $(GO_BUILDFLAGS) -tags 'generate $(GO_TAGS)' GO_COVER_MODE ?= count +CGO_ENABLED ?= 0 export GO111MODULE @@ -172,7 +173,7 @@ ifeq ($(GO_NOCOV),true) else @mkdir -p $(GO_TEST_OUTPUT) @CGO_ENABLED=0 $(GOHOST) test -i -cover $(GO_STATIC_FLAGS) $(GO_PACKAGES) || $(FAIL) - @CGO_ENABLED=0 $(GOHOST) test -v -covermode=$(GO_COVER_MODE) -coverprofile=$(GO_TEST_OUTPUT)/coverage.txt $(GO_TEST_FLAGS) $(GO_STATIC_FLAGS) $(GO_PACKAGES) 2>&1 | tee $(GO_TEST_OUTPUT)/unit-tests.log || $(FAIL) + @CGO_ENABLED=$(CGO_ENABLED) $(GOHOST) test -v -covermode=$(GO_COVER_MODE) -coverprofile=$(GO_TEST_OUTPUT)/coverage.txt $(GO_TEST_FLAGS) $(GO_STATIC_FLAGS) $(GO_PACKAGES) 2>&1 | tee $(GO_TEST_OUTPUT)/unit-tests.log || $(FAIL) @cat $(GO_TEST_OUTPUT)/unit-tests.log | $(GOJUNIT) -set-exit-code > $(GO_TEST_OUTPUT)/unit-tests.xml || $(FAIL) @$(GOCOVER_COBERTURA) < $(GO_TEST_OUTPUT)/coverage.txt > $(GO_TEST_OUTPUT)/coverage.xml endif From 673797e15e7ab142ad3f1478f7cd401bddb2f2c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A9=E5=85=83?= Date: Wed, 11 Nov 2020 08:01:54 +0800 Subject: [PATCH 3/3] address comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 天元 --- makelib/golang.mk | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/makelib/golang.mk b/makelib/golang.mk index ff9549f..3bd1a64 100644 --- a/makelib/golang.mk +++ b/makelib/golang.mk @@ -35,6 +35,8 @@ GO_TAGS ?= GO_TEST_FLAGS ?= GO_TEST_SUITE ?= GO_NOCOV ?= +GO_COVER_MODE ?= count +GO_CGO_ENABLED ?= 0 # ==================================================================================== # Setup go environment @@ -129,8 +131,6 @@ endif GO_COMMON_FLAGS = $(GO_BUILDFLAGS) -tags '$(GO_TAGS)' GO_STATIC_FLAGS = $(GO_COMMON_FLAGS) $(GO_PKG_STATIC_FLAGS) -installsuffix static -ldflags '$(GO_LDFLAGS)' GO_GENERATE_FLAGS = $(GO_BUILDFLAGS) -tags 'generate $(GO_TAGS)' -GO_COVER_MODE ?= count -CGO_ENABLED ?= 0 export GO111MODULE @@ -172,8 +172,8 @@ ifeq ($(GO_NOCOV),true) @CGO_ENABLED=0 $(GOHOST) test $(GO_TEST_FLAGS) $(GO_STATIC_FLAGS) $(GO_PACKAGES) || $(FAIL) else @mkdir -p $(GO_TEST_OUTPUT) - @CGO_ENABLED=0 $(GOHOST) test -i -cover $(GO_STATIC_FLAGS) $(GO_PACKAGES) || $(FAIL) - @CGO_ENABLED=$(CGO_ENABLED) $(GOHOST) test -v -covermode=$(GO_COVER_MODE) -coverprofile=$(GO_TEST_OUTPUT)/coverage.txt $(GO_TEST_FLAGS) $(GO_STATIC_FLAGS) $(GO_PACKAGES) 2>&1 | tee $(GO_TEST_OUTPUT)/unit-tests.log || $(FAIL) + @CGO_ENABLED=$(GO_CGO_ENABLED) $(GOHOST) test -i -cover $(GO_STATIC_FLAGS) $(GO_PACKAGES) || $(FAIL) + @CGO_ENABLED=$(GO_CGO_ENABLED) $(GOHOST) test -v -covermode=$(GO_COVER_MODE) -coverprofile=$(GO_TEST_OUTPUT)/coverage.txt $(GO_TEST_FLAGS) $(GO_STATIC_FLAGS) $(GO_PACKAGES) 2>&1 | tee $(GO_TEST_OUTPUT)/unit-tests.log || $(FAIL) @cat $(GO_TEST_OUTPUT)/unit-tests.log | $(GOJUNIT) -set-exit-code > $(GO_TEST_OUTPUT)/unit-tests.xml || $(FAIL) @$(GOCOVER_COBERTURA) < $(GO_TEST_OUTPUT)/coverage.txt > $(GO_TEST_OUTPUT)/coverage.xml endif