Skip to content

Commit

Permalink
Scatter function coverage reports over related files instead of pick …
Browse files Browse the repository at this point in the history
…first one.

Add to `lines` element to `classes` element for jenkins cobertura-plugin.
  • Loading branch information
t-yuki committed Aug 23, 2013
1 parent 5a6930f commit 79bcf29
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions gocov-xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,33 +66,42 @@ func main() {
// convert packages
packages := make([]Package, len(r.Packages))
for i, gPackage := range r.Packages {
// group functions by "class" (type)
classes := make(map[string]*Class)
// group functions by filename and "class" (type)
files := make(map[string]map[string]*Class)
for _, gFunction := range gPackage.Functions {
classes := files[gFunction.File]
if classes == nil {
// group functions by "class" (type) in a File
classes = make(map[string]*Class)
files[gFunction.File] = classes
}

s := strings.Split("-."+gFunction.Name, ".")
className, methodName := s[len(s)-2], s[len(s)-1]
class := classes[className]
if class == nil {
// type's methods can be in many files, we just pick first
class = &Class{Name: className, Filename: gFunction.File, Methods: []Method{}}
class = &Class{Name: className, Filename: gFunction.File, Methods: []Method{}, Lines: []Line{}}
classes[className] = class
}

// FIXME convert statements to lines
lines := make([]Line, len(gFunction.Statements))
for i, s := range gFunction.Statements {
lines[i] = Line{Number: s.Start, Hits: s.Reached}
class.Lines = append(class.Lines, lines[i])
}

class.Methods = append(class.Methods, Method{Name: methodName, Lines: lines})
}

// fill package with "classes"
p := Package{Name: gPackage.Name, Classes: make([]Class, len(classes))}
p := Package{Name: gPackage.Name, Classes: make([]Class, 0)}
j := 0
for _, class := range classes {
p.Classes[j] = *class
j++
for _, classes := range files {
for _, class := range classes {
p.Classes = append(p.Classes, *class)
j++
}
}
packages[i] = p
}
Expand Down

0 comments on commit 79bcf29

Please sign in to comment.