forked from flowonyx/runtemplate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcoverage
executable file
·45 lines (36 loc) · 1011 Bytes
/
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
#!/bin/bash -e
# cannot use test profile flag with multiple packages, so...
# other useful value is 'html'
#MODE=${1:-func}
DIR=$PWD
DOT=$(dirname $0)
cd $DOT
TOP=$PWD
#go env
# install Goveralls if absent
if ! type -p goveralls; then
echo go get github.com/mattn/goveralls
go get github.com/mattn/goveralls
fi
mkdir -p reports
rm -f reports/*.html coverage?*.*
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 &
else
ls -lh reports/
fi