forked from nytimes/gizmo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coverage.sh
executable file
·45 lines (37 loc) · 968 Bytes
/
coverage.sh
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
37
38
39
40
41
42
43
44
45
#!/bin/bash
set -e
workdir=.cover
profile="$workdir/cover.out"
mode=set
generate_cover_data() {
rm -rf "$workdir"
mkdir "$workdir"
for pkg in "$@"; do
if [ $pkg == "github.com/NYTimes/gizmo/server" -o $pkg == "github.com/NYTimes/gizmo/config" -o $pkg == "github.com/NYTimes/gizmo/web" -o $pkg == "github.com/NYTimes/gizmo/pubsub" ]
then
f="$workdir/$(echo $pkg | tr / -)"
go test -covermode="$mode" -coverprofile="$f.cover" "$pkg"
fi
done
echo "mode: $mode" >"$profile"
grep -h -v "^mode:" "$workdir"/*.cover >>"$profile"
}
show_cover_report() {
go tool cover -${1}="$profile"
}
push_to_coveralls() {
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" ;;
esac
rm -rf "$workdir"