From 92ea9fa108d608a4bd46dc4f51e251e99a2964c5 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Thu, 13 Jun 2013 13:12:58 -0700 Subject: [PATCH] cmd/go: change to use struct in go test -cover Go tool half of https://golang.org/cl/10271044 R=golang-dev, gri CC=golang-dev https://golang.org/cl/10272043 --- src/cmd/go/build.go | 9 ++++----- src/cmd/go/pkg.go | 5 ++--- src/cmd/go/test.go | 7 +++---- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/cmd/go/build.go b/src/cmd/go/build.go index e8f390483c..213489a1a5 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 b399577a5a..31e6da6d34 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 11972cc8cc..f33e56e0f3 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}} }