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)
}
// 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)
}
// 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) {
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++
}
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}}
}