Skip to content

Commit 437a8a9

Browse files
authored
make integ tests count towards code coverage (#178)
1 parent d8d54d3 commit 437a8a9

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

Makefile

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ PROGS = cadence
1919
TEST_ARG ?= -race -v -timeout 5m
2020
BUILD := ./build
2121
TOOLS_CMD_ROOT=./cmd/tools
22+
INTEG_TEST_ROOT=./host
2223

2324
export PATH := $(GOPATH)/bin:$(PATH)
2425

@@ -50,6 +51,21 @@ TOOLS_SRC += $(TOOLS_CMD_ROOT)
5051
# all directories with *_test.go files in them
5152
TEST_DIRS := $(sort $(dir $(filter %_test.go,$(ALL_SRC))))
5253

54+
# dirs that contain integration tests, these need to be treated
55+
# differently to get correct code coverage
56+
INTEG_TEST_DIRS := $(filter $(INTEG_TEST_ROOT)%,$(TEST_DIRS))
57+
# all tests other than integration test fall into the pkg_test category
58+
PKG_TEST_DIRS := $(filter-out $(INTEG_TEST_ROOT)%,$(TEST_DIRS))
59+
60+
61+
# Need the following option to have integration tests
62+
# count towards coverage. godoc below:
63+
# -coverpkg pkg1,pkg2,pkg3
64+
# Apply coverage analysis in each test to the given list of packages.
65+
# The default is for each test to analyze only the package being tested.
66+
# Packages are specified as import paths.
67+
GOCOVERPKG_ARG := -coverpkg="$(PROJECT_ROOT)/common/...,$(PROJECT_ROOT)/service/...,$(PROJECT_ROOT)/client/...,$(PROJECT_ROOT)/tools/..."
68+
5369
vendor/glide.updated: glide.lock glide.yaml
5470
glide install
5571
touch vendor/glide.updated
@@ -77,22 +93,30 @@ test: bins
7793
done;
7894

7995
cover_profile: clean bins_nothrift
80-
@echo Testing packages:
81-
@for dir in $(TEST_DIRS); do \
96+
@mkdir -p $(BUILD)
97+
@echo "mode: atomic" > $(BUILD)/cover.out
98+
99+
@echo Running integration tests:
100+
@time for dir in $(INTEG_TEST_DIRS); do \
101+
mkdir -p $(BUILD)/"$$dir"; \
102+
go test "$$dir" $(TEST_ARG) $(GOCOVERPKG_ARG) -coverprofile=$(BUILD)/"$$dir"/coverage.out || exit 1; \
103+
cat $(BUILD)/"$$dir"/coverage.out | grep -v "mode: atomic" >> $(BUILD)/cover.out; \
104+
done
105+
106+
@echo Running package tests:
107+
@for dir in $(PKG_TEST_DIRS); do \
82108
mkdir -p $(BUILD)/"$$dir"; \
83109
go test "$$dir" $(TEST_ARG) -coverprofile=$(BUILD)/"$$dir"/coverage.out || exit 1; \
110+
cat $(BUILD)/"$$dir"/coverage.out | grep -v "mode: atomic" >> $(BUILD)/cover.out; \
84111
done;
85112

86113
cover: cover_profile
87-
@for dir in $(TEST_DIRS); do \
88-
go tool cover -html=$(BUILD)/"$$dir"/coverage.out; \
89-
done
114+
go tool cover -html=$(BUILD)/cover.out;
90115

91116
cover_ci: cover_profile
92-
@for dir in $(TEST_DIRS); do \
93-
goveralls -coverprofile=$(BUILD)/"$$dir"/coverage.out -service=travis-ci || echo -e "\x1b[31mCoveralls failed\x1b[m"; \
94-
done
117+
goveralls -coverprofile=$(BUILD)/cover.out -service=travis-ci || echo -e "\x1b[31mCoveralls failed\x1b[m"; \
95118

96119
clean:
97-
rm -rf cadence
98-
rm -rf cadence-cassandra-tool
120+
rm -f cadence
121+
rm -f cadence-cassandra-tool
122+
rm -Rf $(BUILD)

0 commit comments

Comments
 (0)