...
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
13stdout 'pkg1 coverage: 0.0% of statements'
14stdout 'pkg2 \S+ coverage: 0.0% of statements \[no tests to run\]'
15stdout 'pkg3 \S+ coverage: 100.0% of statements'
16stdout 'pkg4 \S+ coverage: \[no statements\]'
17
18# Second run to make sure that caching works properly.
19go test -x -cover ./pkg1 ./pkg2 ./pkg3 ./pkg4
20stdout 'pkg1 coverage: 0.0% of statements'
21stdout 'pkg2 \S+ coverage: 0.0% of statements \[no tests to run\]'
22stdout 'pkg3 \S+ coverage: 100.0% of statements'
23stdout 'pkg4 \S+ coverage: \[no statements\]'
24! stderr 'link(\.exe"?)? -'
25! stderr 'compile(\.exe"?)? -'
26! stderr 'cover(\.exe"?)? -'
27stderr 'covdata(\.exe"?)? percent'
28
29# Now add in -coverprofile.
30go test -cover -coverprofile=cov.dat ./pkg1 ./pkg2 ./pkg3 ./pkg4
31stdout 'pkg1 coverage: 0.0% of statements'
32stdout 'pkg2 \S+ coverage: 0.0% of statements \[no tests to run\]'
33stdout 'pkg3 \S+ coverage: 100.0% of statements'
34stdout 'pkg4 \S+ coverage: \[no statements\]'
35
36# Validate
37go tool cover -func=cov.dat
38stdout 'pkg1/a.go:5:\s+F\s+0.0%'
39
40-- go.mod --
41module m
42
43go 1.16
44-- pkg1/a.go --
45package pkg1
46
47import "fmt"
48
49func F() {
50 fmt.Println("pkg1")
51}
52-- pkg2/a.go --
53package pkg2
54
55import "fmt"
56
57func F() {
58 fmt.Println("pkg2")
59}
60-- pkg2/a_test.go --
61package pkg2
62-- pkg3/a.go --
63package pkg3
64
65import "fmt"
66
67func F() {
68 fmt.Println("pkg3")
69}
70-- pkg3/a_test.go --
71package pkg3
72
73import "testing"
74
75func TestF(t *testing.T) {
76 F()
77}
78-- pkg4/a.go --
79package pkg4
80
81type T struct {
82 X bool
83}
84-- pkg4/a_test.go --
85package pkg4
86
87import (
88 "testing"
89)
90
91func TestT(t *testing.T) {
92 _ = T{}
93}
View as plain text