Skip to content

Instantly share code, notes, and snippets.

@paddycarver
Last active January 25, 2021 00:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paddycarver/6f0d85d2763accaf2668 to your computer and use it in GitHub Desktop.
Save paddycarver/6f0d85d2763accaf2668 to your computer and use it in GitHub Desktop.
Testing a Go package with subpackages and getting good coverage reports.
#! /bin/bash
go get -u github.com/golang/lint/golint
go get -u github.com/paddyforan/combinedcoverage
go get -u github.com/wadey/gocovmerge
cd $GOPATH/src/path/to/your/package
go vet $(go list ./... | grep -v '/vendor/')
go list ./... | grep -v /vendor/ | xargs -L1 golint
mkdir -p coverage
rm -rf coverage/*
for pkg in $(go list ./... | grep -v '/vendor/'); do \
echo "################### testing ${pkg} ###################"; \
go test $pkg -v -race -covermode=count -coverprofile=coverage/${pkg//\//.}.out; \
done
combinedcoverage $(find coverage/*.out | grep -v '/vendor/')
gocovmerge $(find coverage/*.out | grep -v '/vendor/') > coverage/total.out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment