Created
May 17, 2017 22:14
-
-
Save binodluitel/1fa7aa295502d0136f4480a93216d23d to your computer and use it in GitHub Desktop.
Golang test coverage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
SCRIPTS_PATH=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) | |
PROJECT_PATH="$(dirname "$SCRIPTS_PATH")" | |
TEST_OUTPUT_PATH=${PROJECT_PATH}/test-reports | |
COV_PATH=${TEST_OUTPUT_PATH}/coverage | |
COV_OUT=${COV_PATH}/cover.out | |
COV_HTML=${COV_PATH}/cover.html | |
rm -rf ${COV_PATH} | |
mkdir -p ${COV_PATH} | |
echo "mode: atomic" > ${COV_OUT} | |
for PKG in $(go list ./... | grep -v /vendor); do | |
PKG_COV_PATH=${COV_PATH}/${PKG}; | |
PKG_COV_FILE=${PKG_COV_PATH}/cover.out; | |
mkdir -p ${PKG_COV_PATH}; | |
go test -v -race -covermode=atomic -coverprofile ${PKG_COV_FILE} ${PKG}; | |
if [ -f ${PKG_COV_FILE} ]; then | |
go tool cover -html=${PKG_COV_FILE} -o=${PKG_COV_PATH}/cover.html; | |
tail -n +2 ${PKG_COV_FILE} >> ${COV_OUT} | |
else | |
continue; | |
fi; | |
done | |
go tool cover -html=${COV_OUT} -o=${COV_HTML}; | |
echo "HTML coverage:" | |
find ${COV_HTML} -name "*.html" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment