LoginSignup
1
1

More than 5 years have passed since last update.

Use the one liner, get coverage of multiple packages !

Last updated at Posted at 2015-07-30

The One Liner

echo "mode: count" > coverage.txt;for pkg in `find . -maxdepth 3 -path '*_test.go' -type f | xargs -I{} dirname {} | uniq`;do go test -covermode=count -coverprofile=temp.cov $pkg && tail -n +2 temp.cov >> coverage.txt || exit 1;rm temp.cov;done

Format

echo "mode: count" > coverage.txt
for pkg in `find . -maxdepth 3 -path '*_test.go' -type f | xargs -I{} dirname {} | uniq`
do
  go test -covermode=count -coverprofile=temp.cov $pkg && tail -n +2 temp.cov >> coverage.txt || exit 1
  rm temp.cov
done

I discover better practice !

echo "mode: count" > coverage.txt
for pkg in `go list -f="{{if .TestGoFiles}}{{.ImportPath}}{{end}}" ./...`
do
  go test -covermode=count -coverprofile=temp.cov $pkg && tail -n +2 temp.cov >> coverage.txt || exit 1
done
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1