#!/bin/bash set -e # Generate coverage for code in ., unless explicitly pointed to something else via the second argument DIR=${2:-.} # Output dir is a temp dir (OSX/Linux compatible), unless explicitly specified through env COVERAGE_DIR OUTPUT=${COVERAGE_DIR:-$(mktemp -d 2>/dev/null || mktemp -d -t machine-coverage)} # Ensure destination exists mkdir -p "${OUTPUT}" # Final cover file, mode PROFILE=${OUTPUT}/cover.out MODE=set # Generate coverage cover() { cd "$DIR" for PKG in $(go list -tags "${BUILDTAGS}" ./... | grep -v "/vendor/" | grep -v "/Godeps/"); do go test -tags "${BUILDTAGS}" -covermode=${MODE} -coverprofile="${OUTPUT}/$(echo ${PKG} | tr "/" "-").cover" "${PKG}" done echo "mode: ${MODE}" > "${PROFILE}" grep -h -v "^mode:" "${OUTPUT}"/*.cover >> "${PROFILE}" go tool cover -html="${PROFILE}" cd - } # Send the results to coveralls report() { go get github.com/mattn/goveralls goveralls -service travis-ci -coverprofile="${PROFILE}" } # Useful only if building remote/headless serve(){ @cd "${DIR}" python -m SimpleHTTPServer 8000 @cd - } case "$1" in # If in the legacy container, serve as well serve) cover serve ;; # Travis does report report) cover report ;; # Default is to just cover, no report *) cover ;; esac