Debian Codegraph @

script/coverage

raw symbols SCIP
1 #!/bin/sh
2 # Generate test coverage statistics for Go packages.
3 #
4 # Works around the fact that `go test -coverprofile` currently does not work
5 # with multiple packages, see https://code.google.com/p/go/issues/detail?id=6909
6 #
7 # Usage: script/coverage [--html|--coveralls]
8 #
9 # --html Additionally create HTML report and open it in browser
10 # --coveralls Push coverage statistics to coveralls.io
11 #
12
13 set -e
14
15 workdir=.cover
16 profile="$workdir/cover.out"
17 mode=count
18
19 generate_cover_data() {
20 rm -rf "$workdir"
21 mkdir "$workdir"
22
23 for pkg in "$@"; do
24 f="$workdir/$(echo $pkg | tr / -).cover"
25 go test -covermode="$mode" -coverprofile="$f" "$pkg"
26 done
27
28 echo "mode: $mode" >"$profile"
29 grep -h -v "^mode:" "$workdir"/*.cover >>"$profile"
30 }
31
32 show_cover_report() {
33 go tool cover -${1}="$profile"
34 }
35
36 push_to_coveralls() {
37 echo "Pushing coverage statistics to coveralls.io"
38 }
39
40 generate_cover_data $(go list ./...)
41 show_cover_report func
42 case "$1" in
43 "")
44 ;;
45 --html)
46 show_cover_report html ;;
47 --coveralls)
48 push_to_coveralls ;;
49 *)
50 echo >&2 "error: invalid option: $1"; exit 1 ;;
51 esac