...
1[short] skip
2
3# Workaround for issue 64014 -- for the portion of this test that
4# verifies that caching works correctly, the cache should theoretically
5# always behave reliably/deterministically, however if other tests are
6# concurrently accessing the cache while this test is running, it can
7# lead to cache lookup failures, which manifest as test failures here.
8# To avoid such flakes, use a separate isolated GOCACHE for this test.
9env GOCACHE=$WORK/cache
10
11# Initial run with simple coverage.
12go test -cover ./pkg1 ./pkg2 ./pkg3 ./pkg4
13[!GOEXPERIMENT:coverageredesign] stdout 'pkg1 \[no test files\]'
14[GOEXPERIMENT:coverageredesign] stdout 'pkg1 coverage: 0.0% of statements'
15stdout 'pkg2 \S+ coverage: 0.0% of statements \[no tests to run\]'
16stdout 'pkg3 \S+ coverage: 100.0% of statements'
17stdout 'pkg4 \S+ coverage: \[no statements\]'
18
19# Second run to make sure that caching works properly.
20go test -x -cover ./pkg1 ./pkg2 ./pkg3 ./pkg4
21[!GOEXPERIMENT:coverageredesign] stdout 'pkg1 \[no test files\]'
22[GOEXPERIMENT:coverageredesign] stdout 'pkg1 coverage: 0.0% of statements'
23stdout 'pkg2 \S+ coverage: 0.0% of statements \[no tests to run\]'
24stdout 'pkg3 \S+ coverage: 100.0% of statements'
25stdout 'pkg4 \S+ coverage: \[no statements\]'
26[GOEXPERIMENT:coverageredesign] ! stderr 'link(\.exe"?)? -'
27! stderr 'compile(\.exe"?)? -'
28! stderr 'cover(\.exe"?)? -'
29[GOEXPERIMENT:coverageredesign] stderr 'covdata(\.exe"?)? percent'
30
31# Now add in -coverprofile.
32go test -cover -coverprofile=cov.dat ./pkg1 ./pkg2 ./pkg3 ./pkg4
33[!GOEXPERIMENT:coverageredesign] stdout 'pkg1 \[no test files\]'
34[GOEXPERIMENT:coverageredesign] stdout 'pkg1 coverage: 0.0% of statements'
35stdout 'pkg2 \S+ coverage: 0.0% of statements \[no tests to run\]'
36stdout 'pkg3 \S+ coverage: 100.0% of statements'
37stdout 'pkg4 \S+ coverage: \[no statements\]'
38
39# Validate
40go tool cover -func=cov.dat
41[GOEXPERIMENT:coverageredesign] stdout 'pkg1/a.go:5:\s+F\s+0.0%'
42
43-- go.mod --
44module m
45
46go 1.16
47-- pkg1/a.go --
48package pkg1
49
50import "fmt"
51
52func F() {
53 fmt.Println("pkg1")
54}
55-- pkg2/a.go --
56package pkg2
57
58import "fmt"
59
60func F() {
61 fmt.Println("pkg2")
62}
63-- pkg2/a_test.go --
64package pkg2
65-- pkg3/a.go --
66package pkg3
67
68import "fmt"
69
70func F() {
71 fmt.Println("pkg3")
72}
73-- pkg3/a_test.go --
74package pkg3
75
76import "testing"
77
78func TestF(t *testing.T) {
79 F()
80}
81-- pkg4/a.go --
82package pkg4
83
84type T struct {
85 X bool
86}
87-- pkg4/a_test.go --
88package pkg4
89
90import (
91 "testing"
92)
93
94func TestT(t *testing.T) {
95 _ = T{}
96}
View as plain text