...
Text file
src/cmd/go/testdata/script/cover_coverprofile_nocoverpkg.txt
1# Testcase for #70244. In this bug we're doing a "go test -coverprofile"
2# run for a pair of packages, the first one without tests and the second
3# one with tests. When writing the profile for the second test, profile
4# data from the first package was leaking into the output (we should
5# only see lines in the output profile for the package whose test is
6# being run).
7
8[short] skip
9
10# Kick off test.
11go test -vet=off -count=1 -coverprofile=cov.p ./...
12
13# Generate a function profile.
14go tool cover -func=cov.p
15
16# Prior to GOEXPERIMENT=coverageredesign we should see no output at all for
17# pkg1 (since it has no tests).
18[!GOEXPERIMENT:coverageredesign] ! stdout 'pkg1'
19
20# With GOEXPERIMENT=coverageredesign enabled we should see zero percent
21# coverage for pkg1's DoSomething, not 100% (as in the bug).
22[GOEXPERIMENT:coverageredesign] stdout 'cov/pkg1/file.go:3:\s+DoSomething\s+0.0%'
23
24-- go.mod --
25module cov
26
27-- pkg1/file.go --
28package pkg1
29
30func DoSomething() bool {
31 return true
32}
33-- pkg2/file.go --
34package pkg2
35
36func DoSomething() bool {
37 return true
38}
39-- pkg2/file_test.go --
40package pkg2
41
42import (
43 "cov/pkg1"
44 "testing"
45)
46
47func TestSmth(t *testing.T) {
48 pkg1.DoSomething()
49 DoSomething()
50}
View as plain text