Skip to content

Commit

Permalink
Ignore invalid lines in cobertuna formatter
Browse files Browse the repository at this point in the history
This prevents the test reporter from crashing when an invalid line
number is detected in the cobertuna.xml coverage file.

While this does not address the actual issue causing invalid line
numbers, it does allow the test reporter to ignore the invalid lines.

Related: SlatherOrg/slather#387
Addresses: #320
  • Loading branch information
Ale Paredes authored and Chris Hulton committed May 14, 2018
1 parent 4a0b05c commit 8f60df0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
24 changes: 14 additions & 10 deletions formatters/cobertura/cobertura.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,21 @@ func (r Formatter) Format() (formatters.Report, error) {
}
sort.Sort(ByLineNum(pf.Lines))
for _, l := range pf.Lines {
for num < l.Num {
sf.Coverage = append(sf.Coverage, formatters.NullInt{})
num++
}
if l.Num <= len(sf.Coverage) {
hits := sf.Coverage[l.Num-1].Int + l.Hits
sf.Coverage[l.Num-1] = formatters.NewNullInt(hits)
if l.Num > 0 {
for num < l.Num {
sf.Coverage = append(sf.Coverage, formatters.NullInt{})
num++
}
if l.Num <= len(sf.Coverage) {
hits := sf.Coverage[l.Num-1].Int + l.Hits
sf.Coverage[l.Num-1] = formatters.NewNullInt(hits)
} else {
ni := formatters.NewNullInt(l.Hits)
sf.Coverage = append(sf.Coverage, ni)
num++
}
} else {
ni := formatters.NewNullInt(l.Hits)
sf.Coverage = append(sf.Coverage, ni)
num++
logrus.Warnf("Invalid line number %d in file %s", l.Num, fileName)
}
}
err = rep.AddSourceFile(sf)
Expand Down
1 change: 1 addition & 0 deletions formatters/cobertura/example.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
<line number="20" hits="5" branch="false" />
<line number="31" hits="3" branch="false" />
<line number="20" hits="7" branch="false" />
<line number="0" hits="3" branch="false" />
</lines>
</class>
<class name="search.ISortedArraySearch" filename="search/ISortedArraySearch.java" line-rate="1.0" branch-rate="1.0" complexity="1.0">
Expand Down

0 comments on commit 8f60df0

Please sign in to comment.