Skip to content

Instantly share code, notes, and snippets.

@Terminator637
Created February 10, 2019 15:57
Show Gist options
  • Save Terminator637/d91ade387def0ccbade2ab31e6eedd15 to your computer and use it in GitHub Desktop.
Save Terminator637/d91ade387def0ccbade2ab31e6eedd15 to your computer and use it in GitHub Desktop.
Script that prints the test coverage of the entire package and generates the coverage in HTML
#!/bin/sh
touch ./coverage.tmp &&
echo 'mode: atomic' > coverage.out &&
go list ./... | grep -v /mocks | grep -v /pb | xargs -n1 -I{} sh -c 'go test -v -race -covermode=atomic -coverprofile=coverage.tmp -coverpkg $(go list ./... | grep -v /mocks | grep -v /pb | tr "\n" ",") {} && tail -n +2 coverage.tmp >> coverage.out || exit 255' && rm coverage.tmp &&
go tool cover -func=coverage.out &&
go tool cover -html=coverage.out -o coverage.html &&
rm coverage.out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment