Skip to content

Commit 473aa7b

Browse files
authored
Do terrible things to make go1.10 coverage reports work (#48)
1 parent b6c82ec commit 473aa7b

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

test-integration.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ SCRATCH_FILE=${COVERFILE}.tmp
1313

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

16+
# go1.10 has an open bug for coverage reports that requires a *terrible* hack
17+
# to workaround. See https://github.com/golang/go/issues/23883 for more details
18+
GO_MINOR_VERSION=$(go version | awk '{print $3}' | cut -d '.' -f 2)
19+
if [ ${GO_MINOR_VERSION} -ge 10 ]; # i.e. we're on go1.10 and up
20+
then
21+
echo "Generating dummy integration file with all the packages listed for coverage"
22+
DUMMY_FILE_PATH=./integration/coverage_imports.go
23+
if [ -f ${DUMMY_FILE_PATH} ]; then
24+
rm -f ${DUMMY_FILE_PATH} # delete file if it exists (only happens when running on a laptop)
25+
fi
26+
# NB: need to do this in two steps or the go compiler compiles the partial file and is :(
27+
generate_dummy_coverage_file integration integration > coverage_imports_file.out
28+
mv coverage_imports_file.out ${DUMMY_FILE_PATH}
29+
fi
30+
1631
# compile the integration test binary
1732
go test -test.c -test.tags=${TAGS} -test.covermode ${COVERMODE} \
1833
-test.coverpkg $(go list ./... | grep -v /vendor/ | paste -sd, -) ./${DIR}

variables.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,28 @@ filter_cover_profile() {
2626
}
2727

2828
export -f filter_cover_profile
29+
30+
# go1.10 has an open bug for coverage reports that requires a *terrible* hack
31+
# to workaround. See https://github.com/golang/go/issues/23883 for more details
32+
function generate_dummy_coverage_file() {
33+
local package_name=$1
34+
local build_tag=$2
35+
go list ./... | grep -v vendor | grep -v "\/${package_name}" > repo_packages.out
36+
INPUT_FILE=./repo_packages.out python <<END
37+
import os
38+
input_file_path = os.environ['INPUT_FILE']
39+
input_file = open(input_file_path)
40+
print '// +build ${build_tag}'
41+
print
42+
print 'package ${package_name}'
43+
print
44+
print 'import ('
45+
for line in input_file.readlines():
46+
line = line.strip()
47+
print '\t _ "%s"' % line
48+
print ')'
49+
print
50+
END
51+
}
52+
53+
export -f generate_dummy_coverage_file

0 commit comments

Comments
 (0)