...
1
2# This test is intended to verify that coverage reporting is consistent
3# between "go test -cover" and "go build -cover" with respect to how
4# the "main" package is handled. See issue 57169 for details.
5
6[short] skip
7[!GOEXPERIMENT:coverageredesign] skip
8
9# Build this program with -cover and run to collect a profile.
10
11go build -cover -o $WORK/prog.exe .
12
13# Save off old GOCOVERDIR setting
14env SAVEGOCOVERDIR=$GOCOVERDIR
15
16mkdir $WORK/covdata
17env GOCOVERDIR=$WORK/covdata
18exec $WORK/prog.exe
19
20# Restore previous GOCOVERDIR setting
21env GOCOVERDIR=$SAVEGOCOVERDIR
22
23# Report percent lines covered.
24go tool covdata percent -i=$WORK/covdata
25stdout '\s*mainwithtest\s+coverage:'
26! stdout 'main\s+coverage:'
27
28# Go test -cover should behave the same way.
29go test -cover .
30stdout 'ok\s+mainwithtest\s+\S+\s+coverage:'
31! stdout 'ok\s+main\s+.*'
32
33
34-- go.mod --
35module mainwithtest
36
37go 1.20
38-- mymain.go --
39package main
40
41func main() {
42 println("hi mom")
43}
44
45func Mainer() int {
46 return 42
47}
48-- main_test.go --
49package main
50
51import "testing"
52
53func TestCoverage(t *testing.T) {
54 println(Mainer())
55}
View as plain text