From dfe35df892923127549d92a5d82f4f5db3eb33bb Mon Sep 17 00:00:00 2001 From: Tony Blyler Date: Thu, 31 Dec 2020 12:11:07 -0500 Subject: [PATCH] add Go coverage helper function --- home/.zshrc.d/golang-helpers.zsh | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 home/.zshrc.d/golang-helpers.zsh diff --git a/home/.zshrc.d/golang-helpers.zsh b/home/.zshrc.d/golang-helpers.zsh new file mode 100755 index 0000000..e984a1b --- /dev/null +++ b/home/.zshrc.d/golang-helpers.zsh @@ -0,0 +1,11 @@ +if command -v go &> /dev/null; then + go_coverage() { + ( + set -eo pipefail + local -r COVERAGE_OUT="$(mktemp)" + go test -cover -coverprofile="${COVERAGE_OUT}" ./... + go tool cover -func="${COVERAGE_OUT}" + rm -f "${COVERAGE_OUT}" + ) + } +fi