forked from alexei-led/pumba
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coverage.sh
executable file
·37 lines (32 loc) · 1.12 KB
/
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
#!/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]
#
# --html Additionally create HTML report and open it in browser
#
[ -z "$COVER" ] && COVER=.cover
profile="$COVER/cover.out"
mode=count
generate_cover_data() {
[ -d "${COVER}" ] && rm -rf "${COVER}/*"
[ -d "${COVER}" ] || mkdir -p "${COVER}"
for pkg in "$@"; do
f="${COVER}/$(echo $pkg | tr / -).cover"
tf="${COVER}/$(echo $pkg | tr / -)_tests.xml"
tout="${COVER}/$(echo $pkg | tr / -)_tests.out"
#go test -v -covermode="$mode" -coverprofile="$f" "$pkg" | go-junit-report > "$tf"
go test -v -covermode="$mode" -coverprofile="$f" "$pkg" | tee "$tout"
cat "$tout" | go-junit-report > "$tf"
done
echo "mode: $mode" >"$profile"
grep -h -v "^mode:" "${COVER}"/*.cover >>"$profile"
}
show_cover_report() {
go tool cover -${1}="$profile" -o "${COVER}/coverage.html"
}
generate_cover_data $(go list ./... | grep -v vendor)
show_cover_report html