Merge pull request #81 from achanda/master

Make make cover work
This commit is contained in:
Mitchell Hashimoto 2015-04-28 19:19:48 -07:00
commit a0bcf1a256
3 changed files with 54 additions and 3 deletions

1
.gitignore vendored
View File

@ -6,6 +6,7 @@
# Folders
_obj
_test
.cover
# Architecture specific extensions/prefixes
*.[568vq]

View File

@ -32,9 +32,7 @@ cover:
@go tool cover 2>/dev/null; if [ $$? -eq 3 ]; then \
go get -u golang.org/x/tools/cmd/cover; \
fi
godep go test $(TEST) -coverprofile=coverage.out
godep go tool cover -html=coverage.out
rm coverage.out
./scripts/coverage.sh --html
# vet runs the Go source code static analysis tool `vet` to find
# any common errors.

52
scripts/coverage.sh Executable file
View File

@ -0,0 +1,52 @@
#!/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"
}
push_to_coveralls() {
echo "Pushing coverage statistics to coveralls.io"
goveralls -coverprofile="$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