https://github.com/etcd-io/etcd
Raw File
Tip revision: e71e0c5c8813d5d071e27514b411d9687bd776ee authored by Gyuho Lee on 18 August 2020, 15:48:09 UTC
Merge pull request #12226 from jingyih/fix_backport_PR12216
Tip revision: e71e0c5
cover.test.bash
#!/usr/bin/env bash
#
# Generate coverage HTML for a package
# e.g. PKG=./unit ./tests/cover.test.bash
#
set -e

if ! [[ "$0" =~ "tests/cover.test.bash" ]]; then
  echo "must be run from repository root"
  exit 255
fi

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