diff --git a/src/cmd/go/build.go b/src/cmd/go/build.go index e8f390483c8..213489a1a5c 100644 --- a/src/cmd/go/build.go +++ b/src/cmd/go/build.go @@ -798,7 +798,7 @@ func (b *builder) build(a *action) (err error) { continue } coverFile := filepath.Join(obj, file) - if err := b.cover(a, coverFile, sourceFile, 0666, cover.Count, cover.Pos); err != nil { + if err := b.cover(a, coverFile, sourceFile, 0666, cover.Var); err != nil { return err } gofiles = append(gofiles, coverFile) @@ -1110,13 +1110,12 @@ func (b *builder) copyFile(a *action, dst, src string, perm os.FileMode) error { } // cover runs, in effect, -// go tool cover -mode=b.coverMode -count="count" -pos="pos" -o dst.go src.go -func (b *builder) cover(a *action, dst, src string, perm os.FileMode, count, pos string) error { +// go tool cover -mode=b.coverMode -var="varName" -o dst.go src.go +func (b *builder) cover(a *action, dst, src string, perm os.FileMode, varName string) error { return b.run(a.objdir, "cover "+a.p.ImportPath, nil, tool("cover"), "-mode", a.p.coverMode, - "-count", count, - "-pos", pos, + "-var", varName, "-o", dst, src) } diff --git a/src/cmd/go/pkg.go b/src/cmd/go/pkg.go index b399577a5a2..31e6da6d345 100644 --- a/src/cmd/go/pkg.go +++ b/src/cmd/go/pkg.go @@ -90,9 +90,8 @@ type Package struct { // CoverVar holds the name of the generated coverage variables targeting the named file. type CoverVar struct { - File string // local file name - Count string // name of count array - Pos string // name of position array + File string // local file name + Var string // name of count struct } func (p *Package) copyBuild(pp *build.Package) { diff --git a/src/cmd/go/test.go b/src/cmd/go/test.go index 11972cc8ccb..f33e56e0f3b 100644 --- a/src/cmd/go/test.go +++ b/src/cmd/go/test.go @@ -682,9 +682,8 @@ func declareCoverVars(files ...string) map[string]*CoverVar { coverVars := make(map[string]*CoverVar) for _, file := range files { coverVars[file] = &CoverVar{ - File: file, - Count: fmt.Sprintf("GoCoverCount_%d", coverIndex), - Pos: fmt.Sprintf("GoCoverPos_%d", coverIndex), + File: file, + Var: fmt.Sprintf("GoCover_%d", coverIndex), } coverIndex++ } @@ -988,7 +987,7 @@ var ( func init() { {{range $file, $cover := .CoverVars}} - coverRegisterFile({{printf "%q" $file}}, _test.{{$cover.Count}}[:], _test.{{$cover.Pos}}[:]...) + coverRegisterFile({{printf "%q" $file}}, _test.{{$cover.Var}}.Count[:], _test.{{$cover.Var}}.Pos[:]...) {{end}} }