mirror of
https://github.com/golang/go
synced 2024-11-22 14:04:48 -07:00
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
This commit is contained in:
parent
568c4617ec
commit
92ea9fa108
@ -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)
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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}}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user