-
Notifications
You must be signed in to change notification settings - Fork 50
/
test-framework-pkg.mk
36 lines (27 loc) · 1.07 KB
/
test-framework-pkg.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# this Makefile can be reused by framework packages for testing
SHELL := $(shell env which bash)
# the name of the directory that contains this Makefile
PKG := $(shell basename $$(pwd))
# a list of this package's Go sources, Go test sources, Go Xtest sources
# (test sources in this directory but belonging to a different package)
#, and Go sources for packages on which this package depends
SRCS := $(shell \
go list -f \
'{{join .GoFiles "\n"}}{{"\n"}}{{join .TestGoFiles "\n"}}{{"\n"}}{{join .XTestGoFiles "\n"}}' \
&& \
go list -f \
'{{with $$p := .}}{{if not $$p.Standard}}{{range $$f := $$p.GoFiles}}{{printf "%s/%s\n" $$p.Dir $$f }}{{end}}{{end}}{{end}}' \
$$(go list -f '{{if not .Standard}}{{join .Deps "\n"}}{{end}}' \
. \
$$(go list -f '{{join .TestImports "\n"}}{{"\n"}}{{join .XTestImports "\n"}}') | sort -u))
# the test binary
$(PKG).test: $(SRCS)
go test -cover -c -o $@ .
# the coverage file
$(PKG).test.out: $(PKG).test
./$< -test.coverprofile $@
build-tests: $(PKG).test
test: $(PKG).test.out
clean:
rm -f $(PKG).test $(PKG).test.out
.PHONY: clean