mirror of https://github.com/docker/docs.git
Merge pull request #78 from jfrazelle/move-coverage-script-to-makefile
Move coverage script to makefile
This commit is contained in:
commit
b91777d51a
|
@ -2,4 +2,5 @@
|
|||
cover
|
||||
bin
|
||||
cross
|
||||
.cover
|
||||
*.swp
|
||||
|
|
|
@ -5,7 +5,8 @@ RUN apt-get update && apt-get install -y \
|
|||
--no-install-recommends \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN go get golang.org/x/tools/cmd/vet
|
||||
RUN go get golang.org/x/tools/cmd/vet \
|
||||
&& go get golang.org/x/tools/cmd/cover
|
||||
|
||||
COPY . /go/src/github.com/docker/notary
|
||||
|
||||
|
|
23
Makefile
23
Makefile
|
@ -7,8 +7,16 @@ GO_LDFLAGS_STATIC=-ldflags "-w -extldflags -static -X `go list ./version`.Versio
|
|||
GOOSES = darwin freebsd linux windows
|
||||
GOARCHS = amd64 386
|
||||
|
||||
# go cover test variables
|
||||
COVERDIR=.cover
|
||||
COVERPROFILE=$(COVERDIR)/cover.out
|
||||
COVERMODE=count
|
||||
PKGS = $(shell go list ./... | tr '\n' ' ')
|
||||
|
||||
.PHONY: clean all fmt vet lint build test binaries cross
|
||||
.DELETE_ON_ERROR: cover
|
||||
.DEFAULT: default
|
||||
|
||||
all: AUTHORS clean fmt vet fmt lint build test binaries
|
||||
|
||||
AUTHORS: .git/HEAD
|
||||
|
@ -56,8 +64,19 @@ test-full: vet lint
|
|||
|
||||
protos:
|
||||
@protoc --go_out=plugins=grpc:. proto/*.proto
|
||||
cov:
|
||||
@sh coverage.sh --html
|
||||
|
||||
|
||||
|
||||
define gocover
|
||||
go test -covermode="$(COVERMODE)" -coverprofile="$(COVERDIR)/$(subst /,-,$(1)).cover" "$(1)";
|
||||
endef
|
||||
|
||||
cover: .cover
|
||||
@mkdir -p "$(COVERDIR)"
|
||||
$(foreach PKG,$(PKGS),$(call gocover,$(PKG)))
|
||||
@echo "mode: $(COVERMODE)" > "$(COVERPROFILE)"
|
||||
@grep -h -v "^mode:" "$(COVERDIR)"/*.cover >> "$(COVERPROFILE)"
|
||||
@go tool cover -func="$(COVERPROFILE)"
|
||||
|
||||
clean-protos:
|
||||
@rm proto/*.pb.go
|
||||
|
|
47
coverage.sh
47
coverage.sh
|
@ -1,47 +0,0 @@
|
|||
#!/bin/sh
|
||||
# Generate test coverage statistics for Go packages.
|
||||
#
|
||||
# Works around the fact that `go test -coverprofile` currently does not work
|
||||
# with multiple packages, see https://code.google.com/p/go/issues/detail?id=6909
|
||||
#
|
||||
# Usage: script/coverage [--html|--coveralls]
|
||||
#
|
||||
# --html Additionally create HTML report and open it in browser
|
||||
# --coveralls Push coverage statistics to coveralls.io
|
||||
#
|
||||
|
||||
set -e
|
||||
|
||||
workdir=.cover
|
||||
profile="$workdir/cover.out"
|
||||
mode=count
|
||||
|
||||
generate_cover_data() {
|
||||
rm -rf "$workdir"
|
||||
mkdir "$workdir"
|
||||
|
||||
for pkg in "$@"; do
|
||||
f="$workdir/$(echo $pkg | tr / -).cover"
|
||||
go test -covermode="$mode" -coverprofile="$f" "$pkg"
|
||||
done
|
||||
|
||||
echo "mode: $mode" >"$profile"
|
||||
grep -h -v "^mode:" "$workdir"/*.cover >>"$profile"
|
||||
}
|
||||
|
||||
show_cover_report() {
|
||||
go tool cover -${1}="$profile"
|
||||
}
|
||||
|
||||
generate_cover_data $(go list ./...)
|
||||
show_cover_report func
|
||||
case "$1" in
|
||||
"")
|
||||
;;
|
||||
--html)
|
||||
show_cover_report html ;;
|
||||
--coveralls)
|
||||
push_to_coveralls ;;
|
||||
*)
|
||||
echo >&2 "error: invalid option: $1"; exit 1 ;;
|
||||
esac
|
Loading…
Reference in New Issue