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 # See the License for the specific language governing permissions and
# limitations under the License. # 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 set -euo pipefail
covermode=${COVERMODE:-atomic} covermode=${COVERMODE:-atomic}
@ -24,31 +35,14 @@ pushd /
hash goveralls 2>/dev/null || go get github.com/mattn/goveralls hash goveralls 2>/dev/null || go get github.com/mattn/goveralls
popd popd
generate_cover_data() { go test -cpu 4 -coverprofile="${profile}" -covermode="$covermode" -coverpkg=./... ./...
for d in $(go list ./...) ; do
(
local output="${coverdir}/${d//\//-}.cover"
go test -coverprofile="${output}" -covermode="$covermode" "$d"
)
done
echo "mode: $covermode" >"$profile" go tool cover -func "${profile}"
grep -h -v "^mode:" "$coverdir"/*.cover >>"$profile"
}
push_to_coveralls() { if [[ "${CIRCLE_BRANCH-}" == 'master' ]]; then
goveralls -coverprofile="${profile}" -service=circle-ci goveralls -coverprofile="${profile}" -service=circle-ci
} fi
generate_cover_data if [[ "${1-}" == '--html' ]]; then
go tool cover -func "${profile}"
case "${1-}" in
--html)
go tool cover -html "${profile}" go tool cover -html "${profile}"
;; fi
--coveralls)
push_to_coveralls
;;
esac

Loading…
Cancel
Save