Goのコードカバレッジをサブパッケージまでまとめて出力
go test -coverprofile=coverage.out ./...
というのが出来ると思ったら、現段階ではまだできないようです。
go.tools/cmd/cover: should support -coverprofile for multiple packages
*.go
が含まれるディレクトリで実行して回って、出力をくっつけるスクリプトを書いて凌ぐことにしました。
profile="coverage.out"
if [ -f $profile ]
then
rm $profile
fi
for dir in $(find . -type d ! -path "*/.git*" ! -path "*/_*")
do
if ls $dir/*.go > /dev/null 2>&1
then
subprofile=$dir/coverage.tmp
go test -coverprofile=$subprofile $dir
if [ -f $subprofile ]
then
if [ -f $profile ]
then
cat $subprofile | tail -n +2 >> $profile
else
cat $subprofile >> $profile
fi
rm $subprofile
fi
fi
done
go tool cover -html=$profile