Skip to content

Commit d06c9b4

Browse files
committed
cmd/go: fix "go test -n -cover" glitch with no-test packages
Invoking "go test -n -cover ./..." on a collection of packages that includes at least one package with code but no tests can result in spurious error of the form my/package: open $WORK/b112/covmeta.b07a5f2dff1231cae3a6bdd70c8cc7c19da16abf8ac59747d8e9859c03594d37: no such file or directory This patch fixes this issue by ensuring that we stub out some of the meta-data file handling for no-test packages if "-n" is in effect. Fixes #67952. Change-Id: Ic6160c275abdec5e5b8beecc6a59accb2b8cfe7d Reviewed-on: https://go-review.googlesource.com/c/go/+/592201 Reviewed-by: Michael Matloob <matloob@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent adc5b55 commit d06c9b4

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/cmd/go/internal/work/cover.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ func BuildActionCoverMetaFile(runAct *Action) (string, error) {
4444
}
4545
if pred.Package.ImportPath == p.ImportPath {
4646
metaFile := pred.Objdir + covcmd.MetaFileForPackage(p.ImportPath)
47+
if cfg.BuildN {
48+
return metaFile, nil
49+
}
4750
f, err := os.Open(metaFile)
4851
if err != nil {
4952
return "", err
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Adding -cover to "go test -n" should not cause failures,
2+
# see issue 67952. In the regular (no "-n") case for an
3+
# empty package test action for the package will look for
4+
# a static meta-data file produced by the cover tool
5+
# during the build action; when "-n" is in effect that
6+
# meta-data file doesn't exist, so the code that reads
7+
# the meta-data file has to be stubbed out.
8+
9+
go test -vet=off -n -cover ./f
10+
11+
-- go.mod --
12+
module M
13+
14+
go 1.21
15+
-- f/f.go --
16+
package f
17+
18+
func Id() int {
19+
return 42
20+
}

0 commit comments

Comments
 (0)