Skip to content

Commit

Permalink
Fix jacoco formatter (#231)
Browse files Browse the repository at this point in the history
* Jacoco formatter was not taking into account the package
  name to create the source file path.
* Update test to check for full filepath
  • Loading branch information
Ale Paredes authored and noahd1 committed Oct 2, 2017
1 parent 08d5649 commit 2f634b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions formatters/jacoco/jacoco.go
Expand Up @@ -2,6 +2,7 @@ package jacoco

import (
"encoding/xml"
"fmt"
"os"
"strings"

Expand Down Expand Up @@ -41,21 +42,22 @@ func (r Formatter) Format() (formatters.Report, error) {
return rep, errors.WithStack(err)
}

c := &xmlFile{}
err = xml.NewDecoder(fx).Decode(c)
xmlJacoco := &xmlFile{}
err = xml.NewDecoder(fx).Decode(xmlJacoco)
if err != nil {
return rep, errors.WithStack(err)
}

gitHead, _ := env.GetHead()
for _, pp := range c.Packages {
for _, pf := range pp.SourceFile {
for _, xmlPackage := range xmlJacoco.Packages {
for _, xmlSF := range xmlPackage.SourceFile {
num := 1
sf, err := formatters.NewSourceFile(pf.Name, gitHead)
filepath := fmt.Sprintf("%s/%s", xmlPackage.Name, xmlSF.Name)
sf, err := formatters.NewSourceFile(filepath, gitHead)
if err != nil {
return rep, errors.WithStack(err)
}
for _, l := range pf.Lines {
for _, l := range xmlSF.Lines {
for num < l.Num {
sf.Coverage = append(sf.Coverage, formatters.NullInt{})
num++
Expand Down
2 changes: 1 addition & 1 deletion formatters/jacoco/jacoco_test.go
Expand Up @@ -23,7 +23,7 @@ func Test_Parse(t *testing.T) {
r.NoError(err)
r.Len(rep.SourceFiles, 3)

sf := rep.SourceFiles["Application.java"]
sf := rep.SourceFiles["be/apo/basic/Application.java"]
r.InDelta(33.3, sf.CoveredPercent, 1)
r.Len(sf.Coverage, 11)
r.True(sf.Coverage[6].Valid)
Expand Down

0 comments on commit 2f634b8

Please sign in to comment.