Skip to content

Instantly share code, notes, and snippets.

@samaita
Created August 20, 2019 07:19
Show Gist options
  • Save samaita/05c10333ba0bdb740f2c6f9ec3d0bf06 to your computer and use it in GitHub Desktop.
Save samaita/05c10333ba0bdb740f2c6f9ec3d0bf06 to your computer and use it in GitHub Desktop.
Bash Script for measure Unit Test coverage percentage for Golang package, skipping vendor
#!/bin/bash
set -e
echo 'mode: count' > profile.cov
for dir in $(find . -maxdepth 10 -not -path './.git*' -not -path '*/_*' -not -path '*/vendor*' -type d);
do
if ls $dir/*.go &> /dev/null; then
go test -short -covermode=count -coverprofile=$dir/profile.tmp $dir
if [ -f $dir/profile.tmp ]
then
cat $dir/profile.tmp | tail -n +2 >> profile.cov
rm $dir/profile.tmp
fi
fi
done
go tool cover -func profile.cov
@samaita
Copy link
Author

samaita commented Aug 20, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment