Rules.mk 1.8 KB
Newer Older
1 2 3 4 5
include mk/header.mk

$(d)/coverage_deps:
	rm -rf $(@D)/unitcover && mkdir $(@D)/unitcover
	rm -rf $(@D)/sharnesscover && mkdir $(@D)/sharnesscover
Jakub Sztandera's avatar
Jakub Sztandera committed
6
ifneq ($(IPFS_SKIP_COVER_BINS),1)
7 8
	go get -u github.com/Kubuxu/gocovmerge
	go get -u golang.org/x/tools/cmd/cover
Jakub Sztandera's avatar
Jakub Sztandera committed
9
endif
10 11 12 13 14 15 16 17 18
.PHONY: $(d)/coverage_deps

# unit tests coverage
UTESTS_$(d) := $(shell go list -f '{{if (len .TestGoFiles)}}{{.ImportPath}}{{end}}' $(go-flags-with-tags) ./... | grep -v go-ipfs/vendor | grep -v go-ipfs/Godeps)

UCOVER_$(d) := $(addsuffix .coverprofile,$(addprefix $(d)/unitcover/, $(subst /,_,$(UTESTS_$(d)))))

$(UCOVER_$(d)): $(d)/coverage_deps ALWAYS
	$(eval TMP_PKG := $(subst _,/,$(basename $(@F))))
19 20 21
	$(eval TMP_DEPS := $(shell go list -f '{{range .Deps}}{{.}} {{end}}' $(go-flags-with-tags) $(TMP_PKG) | sed 's/ /\n/g' | grep ipfs/go-ipfs | grep -v ipfs/go-ipfs/Godeps) $(TMP_PKG))
	$(eval TMP_DEPS_LIST := $(call join-with,$(comma),$(TMP_DEPS)))
	go test $(go-flags-with-tags) $(GOTFLAGS) -covermode=atomic -coverpkg=$(TMP_DEPS_LIST) -coverprofile=$@ $(TMP_PKG)
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36


$(d)/unit_tests.coverprofile: $(UCOVER_$(d))
	gocovmerge $^ > $@

TGTS_$(d) := $(d)/unit_tests.coverprofile


# sharness tests coverage
$(d)/ipfs: GOTAGS += testrunmain
$(d)/ipfs: $(d)/main
	$(go-build)

CLEAN += $(d)/ipfs

37
ifneq ($(filter coverage%,$(MAKECMDGOALS)),)
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
	# this is quite hacky but it is best way I could fiture out
	DEPS_test/sharness += cmd/ipfs/ipfs-test-cover $(d)/coverage_deps $(d)/ipfs
endif

export IPFS_COVER_DIR:= $(realpath $(d))/sharnesscover/

$(d)/sharness_tests.coverprofile: $(d)/ipfs cmd/ipfs/ipfs-test-cover $(d)/coverage_deps test_sharness_short
	(cd $(@D)/sharnesscover && find . -type f | gocovmerge -list -) > $@


PATH := $(realpath $(d)):$(PATH)

TGTS_$(d) += $(d)/sharness_tests.coverprofile

CLEAN += $(TGTS_$(d))
COVERAGE += $(TGTS_$(d))

include mk/footer.mk