https://github.com/etcd-io/etcd
Raw File
Tip revision: fb5cd6f1c72c2b98e0c4453444cdfba306da867b authored by Gyuho Lee on 11 January 2018, 19:19:37 UTC
version: 3.2.14
Tip revision: fb5cd6f
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