mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
32 lines
638 B
Bash
Executable File
32 lines
638 B
Bash
Executable File
#!/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
|