-
Notifications
You must be signed in to change notification settings - Fork 6
/
coverage
executable file
·53 lines (43 loc) · 1.15 KB
/
coverage
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
46
47
48
49
50
51
52
53
#!/bin/bash -e
# Cannot use test profile flag with multiple packages, so this script
# processes each directory in turn.
#
# Other useful value is 'html'
#MODE=${1:-func}
DIR=$PWD
DOT=$(dirname $0)
cd $DOT
TOP=$PWD
PATH=$HOME/go/bin:$PATH
export GO11MODULE=on
#go env
go mod download
# install Goveralls if absent
if ! type -p goveralls; then
echo go install github.com/mattn/goveralls
go install github.com/mattn/goveralls
fi
rm -rf reports
mkdir reports
for file in $(find . -type f -name \*_test.go); do
dirname $file >> coverage$$.tmp
done
sort coverage$$.tmp | uniq | tee coverage$$.dirs
for pkg in $(cat coverage$$.dirs); do
name=$(echo $pkg | sed 's#^./##' | sed 's#/#-#g')
[ "$pkg" = "." ] && name=$(basename $PWD)
echo $pkg becomes $name
go test -v -coverprofile coverage$$.data $pkg
if [ -f coverage$$.data ]; then
go tool cover -html coverage$$.data -o reports/$name.html
unlink coverage$$.data
fi
done
rm -f coverage$$.tmp coverage$$.dirs
if [ -n "$(type -p chromium-browser)" ]; then
chromium-browser reports/*.html >/dev/null &
elif [ -n "$(type -p open)" ]; then
open reports/*.html # >/dev/null &
else
ls -lh reports/
fi