ref(scripts/coverage): simplify test coverage with coverpkg

Signed-off-by: Adam Reese <adam@reese.io>
pull/7947/head
Adam Reese 6 years ago
parent 1911870958
commit 69925b2e1c
No known key found for this signature in database
GPG Key ID: 06F35E60A7A18DD6

@ -14,6 +14,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# coverage.sh - Generate test coverage analysis
#
# Coverage report is sent to coveralls.io if circleci is building the master
# branch.
#
# Usage:
# coverage.sh [option]
#
# Options:
# --html generate html coverage report
set -euo pipefail
covermode=${COVERMODE:-atomic}
@ -24,31 +35,14 @@ pushd /
hash goveralls 2>/dev/null || go get github.com/mattn/goveralls
popd
generate_cover_data() {
for d in $(go list ./...) ; do
(
local output="${coverdir}/${d//\//-}.cover"
go test -coverprofile="${output}" -covermode="$covermode" "$d"
)
done
go test -cpu 4 -coverprofile="${profile}" -covermode="$covermode" -coverpkg=./... ./...
echo "mode: $covermode" >"$profile"
grep -h -v "^mode:" "$coverdir"/*.cover >>"$profile"
}
go tool cover -func "${profile}"
push_to_coveralls() {
if [[ "${CIRCLE_BRANCH-}" == 'master' ]]; then
goveralls -coverprofile="${profile}" -service=circle-ci
}
generate_cover_data
go tool cover -func "${profile}"
fi
case "${1-}" in
--html)
if [[ "${1-}" == '--html' ]]; then
go tool cover -html "${profile}"
;;
--coveralls)
push_to_coveralls
;;
esac
fi

Loading…
Cancel
Save