forked from taskcluster/taskcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gotestcover.sh
executable file
·30 lines (26 loc) · 1.06 KB
/
gotestcover.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash -exv
# This script is needed because `go test -covermode=atomic` cover doesn't
# currently support being run against multiple packages
ENGINE="${1}"
REPORT="${2}"
if [ -z "${REPORT}" ]; then
echo "Specify build tags and a report filename, e.g. '${0}' 'multiuser' myreport.txt" >&2
exit 64
fi
cd "$(dirname "${0}")"
TEMP_SINGLE_REPORT="$(mktemp -t coverage.tmp.XXXXXXXXXX)"
echo "mode: atomic" > "${REPORT}"
HEAD_REV="$(git rev-parse HEAD)"
# Dump package list to file rather than pipe, to avoid exit inside loop not
# causing outer shell to exit due to running in a subshell.
PACKAGE_LIST="$(mktemp -t package-list.tmp.XXXXXXXXXX)"
go list ./... > "${PACKAGE_LIST}"
while read package
do
CGO_ENABLED=1 go test -tags "${ENGINE}" -ldflags "-X github.com/taskcluster/generic-worker.revision=${HEAD_REV}" -v -race -timeout 1h -covermode=atomic "-coverprofile=${TEMP_SINGLE_REPORT}" "${package}"
if [ -f "${TEMP_SINGLE_REPORT}" ]; then
sed 1d "${TEMP_SINGLE_REPORT}" >> "${REPORT}"
rm "${TEMP_SINGLE_REPORT}"
fi
done < "${PACKAGE_LIST}"
rm "${PACKAGE_LIST}"