2019-01-02 20:04:45 -08:00
|
|
|
#!/bin/bash -e
|
|
|
|
|
|
|
|
|
|
main=$1
|
|
|
|
|
coverprofile=$2
|
|
|
|
|
|
|
|
|
|
# Temporary working directory.
|
2020-01-03 17:32:09 -08:00
|
|
|
workdir=$(mktemp -d tmpXXXXXXXX)
|
2019-01-02 20:04:45 -08:00
|
|
|
|
|
|
|
|
# Wrap the main function in a go test.
|
|
|
|
|
cp ${main} ${workdir}
|
|
|
|
|
cat > ${workdir}/main_test.go <<EOF
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
|
|
func TestRunMain(t *testing.T) {
|
|
|
|
|
main()
|
|
|
|
|
}
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
# Execute the test with coverage.
|
|
|
|
|
testbin="${workdir}/testbin"
|
|
|
|
|
output="${workdir}/cover.out"
|
2021-11-12 18:35:36 -08:00
|
|
|
go test -tags=integration -o ${testbin} -covermode=count -coverpkg="github.com/mmcloughlin/avo/..." ${workdir}/*.go
|
2019-01-02 20:04:45 -08:00
|
|
|
${testbin} -test.coverprofile=${output}
|
|
|
|
|
cp ${output} ${coverprofile}
|
|
|
|
|
|
|
|
|
|
# Cleanup.
|
|
|
|
|
rm -rf ${workdir}
|