Revision 35c6ea7a6794aeb67c1a6aa0a9452f2871902119 authored by Gyuho Lee on 27 March 2018, 17:31:05 UTC, committed by Joe Betz on 28 March 2018, 19:39:59 UTC
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
1 parent 8eeab58
Raw File
cover
#!/usr/bin/env bash
#
# Generate coverage HTML for a package
# e.g. PKG=./unit ./cover
#
set -e

if [ -z "$PKG" ]; then
	echo "cover only works with a single package, sorry"
	exit 255
fi

COVEROUT="coverage"

if ! [ -d "$COVEROUT" ]; then
	mkdir "$COVEROUT"
fi

# strip leading dot/slash and trailing slash and sanitize other slashes
# e.g. ./etcdserver/etcdhttp/ ==> etcdserver_etcdhttp
COVERPKG=${PKG/#./}
COVERPKG=${COVERPKG/#\//}
COVERPKG=${COVERPKG/%\//}
COVERPKG=${COVERPKG//\//_}

# generate arg for "go test"
export COVER="-coverprofile ${COVEROUT}/${COVERPKG}.out"

source ./test

go tool cover -html=${COVEROUT}/${COVERPKG}.out
back to top