Skip to content

Commit b0a9e70

Browse files
committed
Improved makefile rules to build profile.out, fixed overlapping results, switched to covermode=count
1 parent 4b594da commit b0a9e70

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

Makefile

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ GOCLEAN ?= $(GOCMD) clean
55
GOINSTALL ?= $(GOCMD) install
66
GOTEST ?= $(GOCMD) test
77
GOFMT ?= gofmt -w
8+
GOCOVER ?= $(GOTEST) -covermode=count -v
89

910
FPM_VERSION ?= $(shell ./dist/scw-Darwin-i386 --version | sed 's/.*v\([0-9.]*\),.*/\1/g')
1011
FPM_DOCKER ?= \
@@ -24,22 +25,22 @@ FPM_ARGS ?= \
2425

2526
NAME = scw
2627
SRC = cmd/scw
27-
PACKAGES = pkg/api pkg/commands pkg/utils pkg/cli pkg/sshcommand pkg/config
28+
PACKAGES = pkg/api pkg/commands pkg/utils pkg/cli pkg/sshcommand pkg/config pkg/scwversion
2829
REV = $(shell git rev-parse HEAD || echo "nogit")
2930
TAG = $(shell git describe --tags --always || echo "nogit")
3031
BUILDER = scaleway-cli-builder
31-
32+
ALL_GO_FILES = $(shell find . -type f -name "*.go")
3233

3334
BUILD_LIST = $(foreach int, $(SRC), $(int)_build)
3435
CLEAN_LIST = $(foreach int, $(SRC) $(PACKAGES), $(int)_clean)
3536
INSTALL_LIST = $(foreach int, $(SRC), $(int)_install)
3637
IREF_LIST = $(foreach int, $(SRC) $(PACKAGES), $(int)_iref)
3738
TEST_LIST = $(foreach int, $(SRC) $(PACKAGES), $(int)_test)
3839
FMT_LIST = $(foreach int, $(SRC) $(PACKAGES), $(int)_fmt)
39-
COVER_LIST = $(foreach int, $(PACKAGES), $(int)_cover)
40+
COVERPROFILE_LIST = $(foreach int, $(PACKAGES), $(int)/profile.out)
4041

4142

42-
.PHONY: $(CLEAN_LIST) $(TEST_LIST) $(FMT_LIST) $(INSTALL_LIST) $(BUILD_LIST) $(IREF_LIST) $(COVER_LIST)
43+
.PHONY: $(CLEAN_LIST) $(TEST_LIST) $(FMT_LIST) $(INSTALL_LIST) $(BUILD_LIST) $(IREF_LIST)
4344

4445

4546
all: build
@@ -50,15 +51,6 @@ test: $(TEST_LIST)
5051
iref: $(IREF_LIST)
5152
fmt: $(FMT_LIST)
5253

53-
noop =
54-
comma = ,
55-
space = $(noop) $(noop)
56-
57-
cover:
58-
rm -f profile.out
59-
$(MAKE) $(COVER_LIST)
60-
echo "mode: set" | cat - profile.out > profile.out.tmp && mv profile.out.tmp profile.out
61-
6254

6355
.git:
6456
touch $@
@@ -81,10 +73,6 @@ $(IREF_LIST): %_iref: pkg/scwversion/version.go
8173
$(GOTEST) -i ./$*
8274
$(TEST_LIST): %_test:
8375
$(GOTEST) ./$*
84-
$(COVER_LIST): %_cover:
85-
#$(GOTEST) -covermode=set -coverpkg=$(subst $(space),$(comma),$(addprefix ./, $(PACKAGES))) -v -coverprofile=file-profile.out ./$*
86-
$(GOTEST) -covermode=set -v -coverprofile=file-profile.out ./$*
87-
if [ -f file-profile.out ]; then cat file-profile.out | grep -v "mode: set" >> profile.out || true; rm -f file-profile.out; fi
8876
$(FMT_LIST): %_fmt:
8977
$(GOFMT) ./$*
9078

@@ -161,9 +149,22 @@ travis_login:
161149
fi
162150

163151

152+
.PHONY: cover
153+
cover: profile.out
154+
155+
$(COVERPROFILE_LIST): $(ALL_GO_FILES)
156+
rm -f $@
157+
$(GOCOVER) -coverpkg=./pkg/... -coverprofile=$@ ./$(dir $@)
158+
159+
profile.out: $(COVERPROFILE_LIST)
160+
rm -f $@
161+
echo "mode: set" > $@
162+
cat ./pkg/*/profile.out | grep -v mode: | sort -r | awk '{if($$1 != last) {print $$0;last=$$1}}' >> $@
163+
164+
164165
.PHONY: travis_coveralls
165166
travis_coveralls:
166-
if [ -f ~/.scwrc ]; then goveralls -service=travis-ci -v -coverprofile=profile.out; fi
167+
if [ -f ~/.scwrc ]; then goveralls -covermode=count -service=travis-ci -v -coverprofile=profile.out; fi
167168

168169

169170
.PHONY: travis_cleanup

0 commit comments

Comments
 (0)