Skip to content

Commit

Permalink
Add coverage script to project
Browse files Browse the repository at this point in the history
  • Loading branch information
sbstjn committed Oct 16, 2016
1 parent cce1bcc commit 78e5ad1
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.cover
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
**allot** is a small library to parse and define strings with placeholders and check if others strings are matching the defined string. This can be useful when using a command line tool, writing a slack bot or some other crazy ideas …

See the [hanu Slackbot](https://github.com/sbstjn/hanu) framework for a usecase for **allot**.

## Credits
* [Go coverage script from Mathias Lafeldt](https://mlafeldt.github.io/blog/test-coverage-in-go/)
52 changes: 52 additions & 0 deletions script/covarage
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/sh
# Generate test coverage statistics for Go packages.
#
# 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]
#
# --html Additionally create HTML report and open it in browser
# --coveralls Push coverage statistics to coveralls.io
#

set -e

workdir=.cover
profile="$workdir/cover.out"
mode=count

generate_cover_data() {
rm -rf "$workdir"
mkdir "$workdir"

for pkg in "$@"; do
f="$workdir/$(echo $pkg | tr / -).cover"
go test -covermode="$mode" -coverprofile="$f" "$pkg"
done

echo "mode: $mode" >"$profile"
grep -h -v "^mode:" "$workdir"/*.cover >>"$profile"
}

show_cover_report() {
go tool cover -${1}="$profile"
}

push_to_coveralls() {
echo "Pushing coverage statistics to coveralls.io"
/home/ubuntu/.go_workspace/bin/goveralls -coverprofile="$profile" -service=circle-ci -repotoken=$COVERALLS_REPO_TOKEN
}

generate_cover_data $(go list ./...)
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

0 comments on commit 78e5ad1

Please sign in to comment.