Created
August 31, 2013 18:57
-
-
Save kisom/6399969 to your computer and use it in GitHub Desktop.
Go test code coverage.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ -z "$1" ]; then | |
PKG=$(pwd) | |
PKG=${PKG##${GOPATH}/src/} | |
else | |
PKG=$1 | |
fi | |
OUTBASE=${PKG##*/} | |
SLOC=$(gofmt -comments=false $(find ${GOPATH}/src/${PKG} -iname \*.go | xargs)\ | |
| sed -e '/^$/d' | wc -l) | |
echo "$SLOC lines of code." | |
go test -test.covermode count -test.coverprofile ${OUTBASE}.out $PKG | |
if [ -e ${OUTBASE}.out ]; then | |
go tool cover -html ${OUTBASE}.out -o ${OUTBASE}.html | |
if [ -e ${OUTBASE}.html ]; then | |
firefox -new-tab file://$(pwd)/${OUTBASE}.html | |
else | |
echo "No HTML file was generated." | |
fi | |
else | |
echo "No coverage profile generated." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment