blob: b7ad391136b68a3a0f93b5b22d1e7ab091717da0 [file] [log] [blame]
khenaidooffe076b2019-01-15 16:08:08 -05001#!/usr/bin/env bash
2#
3# Generate coverage HTML for a package
4# e.g. PKG=./unit ./cover
5#
6set -e
7
8if [ -z "$PKG" ]; then
9 echo "cover only works with a single package, sorry"
10 exit 255
11fi
12
13COVEROUT="coverage"
14
15if ! [ -d "$COVEROUT" ]; then
16 mkdir "$COVEROUT"
17fi
18
19# strip leading dot/slash and trailing slash and sanitize other slashes
20# e.g. ./etcdserver/etcdhttp/ ==> etcdserver_etcdhttp
21COVERPKG=${PKG/#./}
22COVERPKG=${COVERPKG/#\//}
23COVERPKG=${COVERPKG/%\//}
24COVERPKG=${COVERPKG//\//_}
25
26# generate arg for "go test"
27export COVER="-coverprofile ${COVEROUT}/${COVERPKG}.out"
28
29source ./test
30
31go tool cover -html=${COVEROUT}/${COVERPKG}.out