-
-
Save wiedzmin/ac3a20887b70a4aa0c16eafbe35ad6d6 to your computer and use it in GitHub Desktop.
Golang test all packages and combine cover profiles
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
#!/bin/bash | |
# https://gist.github.com/cdennison/cba009cf297aa2a92759278b5c578ae4 | |
# This script tests multiple packages and creates a consolidated cover profile that's almost identical to coveralls/goveralls | |
# https://github.com/mattn/goveralls | |
# | |
# Inspired by | |
# https://github.com/getlantern/flashlight-build/blob/devel/testandcover.bash | |
function die() { | |
echo $* | |
exit 1 | |
} | |
export GOPATH=`pwd`:$GOPATH | |
# Initialize profile.cov | |
echo "mode: count" > profile.cov | |
# Initialize error tracking | |
ERROR="" | |
# Test each package and append coverage profile info to profile.cov | |
for pkg in $(go list ./...) | |
do | |
echo "TESTING $pkg" | |
#$HOME/gopath/bin/ | |
go test -v -covermode=count -coverprofile=profile_tmp.cov -coverpkg=./... $pkg || ERROR="Error testing $pkg" | |
tail -n +2 profile_tmp.cov >> profile.cov || die "Unable to append coverage for $pkg" | |
done | |
if [ ! -z "$ERROR" ] | |
then | |
die "Encountered error, last error was: $ERROR" | |
else | |
go tool cover -func=profile.cov | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment