Skip to content

Commit

Permalink
updates to code coverage scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Snellbaker committed Oct 9, 2017
1 parent cea6273 commit 4a3768b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Folders
_obj
_test
.cover/

# Architecture specific extensions/prefixes
*.[568vq]
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ install:
- glide install

script:
- ./validate.sh --nofmt
- ./validate.sh --nofmt --cov
10 changes: 3 additions & 7 deletions scripts/check_coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ CHECKCOV=false

#cleanup
finish() {
cat scripts/results.tmp
if [ -e "scripts/results.tmp" ]; then
rm scripts/results.tmp
fi

if [ -d ".cover" ]; then
rm -rf .cover
Expand All @@ -19,16 +15,16 @@ finish() {
trap finish EXIT ERR INT TERM

#start script logic
./scripts/coverage.sh > scripts/results.tmp
OUTPUT=`./scripts/coverage.sh`

while read -r LINE; do
if [[ $LINE =~ "%" ]]; then
PERCENT=$(echo "$LINE"|cut -d: -f2- |cut -d% -f1| cut -d. -f1|tr -d ' ')
PERCENT=$(echo "$LINE"|cut -d: -f2-|cut -d% -f1|cut -d. -f1|tr -d ' ')
if [[ $PERCENT -lt 20 ]]; then
CHECKCOV=true
fi
fi
done < scripts/results.tmp
done < "$OUTPUT"

if $CHECKCOV; then
echo "Detected at least one package had less than 20% code coverage. Please review results below or from your terminal run ./scripts/coverage.sh --html for more detailed results"
Expand Down
10 changes: 1 addition & 9 deletions scripts/coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
# Works around the fact that `go test -coverprofile` currently does not work
# with multiple packages, see https://code.google.com/p/go/issues/detail?id=6909
#
# Usage: script/coverage [--html|--coveralls]
# Usage: script/coverage.sh [--html]
#
# --html Additionally create HTML report and open it in browser
# --coveralls Push coverage statistics to coveralls.io
#

set -e
Expand All @@ -33,20 +32,13 @@ show_cover_report() {
go tool cover -${1}="$profile"
}

push_to_coveralls() {
echo "Pushing coverage statistics to coveralls.io"
goveralls -coverprofile="$profile"
}

generate_cover_data $(go list ./... | grep -v /vendor/)
#show_cover_report func
case "$1" in
"")
;;
--html)
show_cover_report html ;;
--coveralls)
push_to_coveralls ;;
*)
echo >&2 "error: invalid option: $1"; exit 1 ;;
esac
9 changes: 7 additions & 2 deletions validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
set -e

AUTOFMT=true
COVERAGE=false

while true; do
case "$1" in
--nofmt ) AUTOFMT=false; shift ;;
--cov ) COVERAGE=true; shift ;;
* ) break ;;
esac
done
Expand All @@ -29,5 +31,8 @@ else
test $GOFMT_LINES -eq 0 || die "gofmt needs to be run, ${GOFMT_LINES} files have issues. Below is a list of files to review:\n`gofmt -l *.go pbs adapters`"
fi

#go test $(go list ./... | grep -v /vendor/)
./scripts/check_coverage.sh
if $COVERAGE; then
./scripts/check_coverage.sh
else
go test $(go list ./... | grep -v /vendor/)
fi

0 comments on commit 4a3768b

Please sign in to comment.