File: covermain

package info (click to toggle)
golang-github-mmcloughlin-avo 0.0~git20200523.4439b6b-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 8,304 kB
  • sloc: xml: 71,029; asm: 13,138; sh: 179; makefile: 35
file content (29 lines) | stat: -rwxr-xr-x 573 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash -e

main=$1
coverprofile=$2

# Temporary working directory.
workdir=$(mktemp -d tmpXXXXXXXX)

# 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"
go test -o ${testbin} -covermode=count -coverpkg="github.com/mmcloughlin/avo/..." ${workdir}/*.go
${testbin} -test.coverprofile=${output}
cp ${output} ${coverprofile}

# Cleanup.
rm -rf ${workdir}