Commit 92ea9fa1 authored by Rob Pike's avatar Rob Pike

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
parent 568c4617
...@@ -798,7 +798,7 @@ func (b *builder) build(a *action) (err error) { ...@@ -798,7 +798,7 @@ func (b *builder) build(a *action) (err error) {
continue continue
} }
coverFile := filepath.Join(obj, file) 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 return err
} }
gofiles = append(gofiles, coverFile) gofiles = append(gofiles, coverFile)
...@@ -1110,13 +1110,12 @@ func (b *builder) copyFile(a *action, dst, src string, perm os.FileMode) error { ...@@ -1110,13 +1110,12 @@ func (b *builder) copyFile(a *action, dst, src string, perm os.FileMode) error {
} }
// cover runs, in effect, // cover runs, in effect,
// go tool cover -mode=b.coverMode -count="count" -pos="pos" -o dst.go src.go // 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, count, pos string) error { 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, return b.run(a.objdir, "cover "+a.p.ImportPath, nil,
tool("cover"), tool("cover"),
"-mode", a.p.coverMode, "-mode", a.p.coverMode,
"-count", count, "-var", varName,
"-pos", pos,
"-o", dst, "-o", dst,
src) src)
} }
......
...@@ -90,9 +90,8 @@ type Package struct { ...@@ -90,9 +90,8 @@ type Package struct {
// CoverVar holds the name of the generated coverage variables targeting the named file. // CoverVar holds the name of the generated coverage variables targeting the named file.
type CoverVar struct { type CoverVar struct {
File string // local file name File string // local file name
Count string // name of count array Var string // name of count struct
Pos string // name of position array
} }
func (p *Package) copyBuild(pp *build.Package) { func (p *Package) copyBuild(pp *build.Package) {
......
...@@ -682,9 +682,8 @@ func declareCoverVars(files ...string) map[string]*CoverVar { ...@@ -682,9 +682,8 @@ func declareCoverVars(files ...string) map[string]*CoverVar {
coverVars := make(map[string]*CoverVar) coverVars := make(map[string]*CoverVar)
for _, file := range files { for _, file := range files {
coverVars[file] = &CoverVar{ coverVars[file] = &CoverVar{
File: file, File: file,
Count: fmt.Sprintf("GoCoverCount_%d", coverIndex), Var: fmt.Sprintf("GoCover_%d", coverIndex),
Pos: fmt.Sprintf("GoCoverPos_%d", coverIndex),
} }
coverIndex++ coverIndex++
} }
...@@ -988,7 +987,7 @@ var ( ...@@ -988,7 +987,7 @@ var (
func init() { func init() {
{{range $file, $cover := .CoverVars}} {{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}} {{end}}
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment