Skip to content

Commit 0600934

Browse files
committed
Makefile: simplify and fix test targets
1. Honor GO_FLAGS; if unset, use -race. As a result, integration tests are now built with -race. 2. Instead of using -short to avoid integration tests, filter out packages under integration. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent b36502e commit 0600934

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

Makefile

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
GO := go
1616
GOLANGCI_VER := v1.42.1
17-
pkgs = $(shell $(GO) list ./... | grep -v vendor)
18-
cmd_pkgs = $(shell cd cmd && $(GO) list ./... | grep -v vendor)
17+
GO_TEST ?= $(GO) test $(or $(GO_FLAGS),-race)
1918
arch ?= $(shell go env GOARCH)
2019

2120
ifeq ($(arch), amd64)
@@ -29,13 +28,12 @@ all: presubmit build test
2928

3029
test:
3130
@echo ">> running tests"
32-
@$(GO) test -short -race $(pkgs)
33-
@cd cmd && $(GO) test -short -race $(cmd_pkgs)
31+
@# Filter out integration.
32+
$(GO) list ./... | grep -vw integration | xargs $(GO_TEST)
33+
cd cmd && $(GO_TEST) ./...
3434

35-
test-with-libpfm:
36-
@echo ">> running tests"
37-
@$(GO) test -short -race -tags="libpfm" $(pkgs)
38-
@cd cmd && $(GO) test -short -race -tags="libpfm" $(cmd_pkgs)
35+
test-with-libpfm: GO_FLAGS=-race -tags libpfm
36+
test-with-libpfm: test
3937

4038
container-test:
4139
@echo ">> runinng tests in a container"
@@ -45,9 +43,9 @@ docker-test: container-test
4543
@echo "docker-test target is deprecated, use container-test instead"
4644

4745
test-integration:
48-
@GO_FLAGS=${$GO_FLAGS:-"-race"} ./build/build.sh
49-
go test -c github.com/google/cadvisor/integration/tests/api
50-
go test -c github.com/google/cadvisor/integration/tests/healthz
46+
GO_FLAGS=$(or $(GO_FLAGS),-race) ./build/build.sh
47+
$(GO_TEST) -c github.com/google/cadvisor/integration/tests/api
48+
$(GO_TEST) -c github.com/google/cadvisor/integration/tests/healthz
5149
@./build/integration.sh
5250

5351
docker-test-integration:

0 commit comments

Comments
 (0)