-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathcoverage.sh
executable file
·41 lines (33 loc) · 990 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
#!/bin/bash -e
# Developer tool to run the tests and obtain HTML coverage reports.
DIR=$PWD
DOT="$(dirname $0)"
cd $DOT
TOP=$PWD
# install Goveralls if absent
if ! type -p goveralls; then
echo go install github.com/mattn/goveralls
go install github.com/mattn/goveralls
fi
mkdir -p reports
rm -f reports/*.html coverage?*.*
for file in $(find . -type f -name \*_test.go | fgrep -v vendor/); 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