Skip to content

Do terrible things to make go1.10 coverage reports work #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions test-integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ SCRATCH_FILE=${COVERFILE}.tmp

echo "mode: ${COVERMODE}" > $SCRATCH_FILE

# go1.10 has an open bug for coverage reports that requires a *terrible* hack
# to workaround. See https://github.com/golang/go/issues/23883 for more details
GO_MINOR_VERSION=$(go version | awk '{print $3}' | cut -d '.' -f 2)
if [ ${GO_MINOR_VERSION} -ge 10 ]; # i.e. we're on go1.10 and up
then
echo "Generating dummy integration file with all the packages listed for coverage"
DUMMY_FILE_PATH=./integration/coverage_imports.go
if [ -f ${DUMMY_FILE_PATH} ]; then
rm -f ${DUMMY_FILE_PATH} # delete file if it exists (only happens when running on a laptop)
fi
# NB: need to do this in two steps or the go compiler compiles the partial file and is :(
generate_dummy_coverage_file integration integration > coverage_imports_file.out
mv coverage_imports_file.out ${DUMMY_FILE_PATH}
fi

# compile the integration test binary
go test -test.c -test.tags=${TAGS} -test.covermode ${COVERMODE} \
-test.coverpkg $(go list ./... | grep -v /vendor/ | paste -sd, -) ./${DIR}
Expand Down
25 changes: 25 additions & 0 deletions variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,28 @@ filter_cover_profile() {
}

export -f filter_cover_profile

# go1.10 has an open bug for coverage reports that requires a *terrible* hack
# to workaround. See https://github.com/golang/go/issues/23883 for more details
function generate_dummy_coverage_file() {
local package_name=$1
local build_tag=$2
go list ./... | grep -v vendor | grep -v "\/${package_name}" > repo_packages.out
INPUT_FILE=./repo_packages.out python <<END
import os
input_file_path = os.environ['INPUT_FILE']
input_file = open(input_file_path)
print '// +build ${build_tag}'
print
print 'package ${package_name}'
print
print 'import ('
for line in input_file.readlines():
line = line.strip()
print '\t _ "%s"' % line
print ')'
print
END
}

export -f generate_dummy_coverage_file