Skip to content

Instantly share code, notes, and snippets.

@kisom
Created October 19, 2014 01:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kisom/3d89ab20259b65be92c3 to your computer and use it in GitHub Desktop.
Save kisom/3d89ab20259b65be92c3 to your computer and use it in GitHub Desktop.
gtcov
#!/bin/sh
# Produce an HTML file displaying code coverage. Dependencies:
# - cloc (apt-get install cloc)
# - cover (go get code.google.com/p/go.tools/cmd/cover)
if [ -z "$1" ]; then
PKG=""
else
PKG=$1
fi
BROWSER=firefox
BROWSER_ARGS="-new-tab"
OUTBASE=cover
SLOC="$(cloc . | grep ^Go | awk '{print $5}')"
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
$BROWSER $BROWSER_ARGS file://$(pwd)/${OUTBASE}.html
# rm ${OUTBASE}.html
else
echo "No HTML file was generated."
fi
rm ${OUTBASE}.out
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