github.com/prebid/prebid-server/v2@v2.18.0/scripts/coverage.sh (about) 1 #!/bin/bash 2 # Generate test coverage statistics for Go packages. 3 # 4 # Works around the fact that `go test -coverprofile` currently does not work 5 # with multiple packages, see https://code.google.com/p/go/issues/detail?id=6909 6 # 7 # Usage: script/coverage.sh [--html] 8 # 9 # --html Additionally create HTML report and open it in browser 10 # 11 12 set -e 13 14 workdir=.cover 15 profile="$workdir/cover.out" 16 mode=count 17 18 generate_cover_data() { 19 rm -rf "$workdir" 20 mkdir "$workdir" 21 22 for pkg in "$@"; do 23 f="$workdir/$(echo $pkg | tr / -).cover" 24 cover="" 25 if ! [[ "$pkg" =~ ^github\.com\/prebid\/prebid\-server$ ]]; then 26 cover="-covermode=$mode -coverprofile=$f" 27 fi 28 go test ${cover} "$pkg" 29 done 30 31 echo "mode: $mode" >"$profile" 32 grep -h -v "^mode:" "$workdir"/*.cover >>"$profile" 33 } 34 35 show_cover_report() { 36 go tool cover -${1}="$profile" 37 } 38 39 generate_cover_data $(go list ./... | grep -v /vendor/) 40 #show_cover_report func 41 case "$1" in 42 "") 43 ;; 44 --html) 45 show_cover_report html ;; 46 *) 47 echo >&2 "error: invalid option: $1"; exit 1 ;; 48 esac