Skip to content

Commit

Permalink
fix LH and LF calculation (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
jandelgado committed Apr 26, 2020
1 parent af019e7 commit 01d5e75
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# changelog for gcov2lcov

## 1.0.2 [2020-04-25]

* fix calculation of LH and LF values which led to wrong calculation of
test coverage in coveralls

## 1.0.1 [2020-04-25]

* avoid duplicate DA records for same lines (see
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test:
go test ./... -coverprofile coverage.out
go tool cover -func coverage.out

inttest:
inttest: build
./bin/gcov2lcov -infile testdata/coverage.out -outfile coverage.lcov
diff testdata/coverage_expected.lcov coverage.lcov
diff -y testdata/coverage_expected.lcov coverage.lcov

10 changes: 5 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ func writeLcovRecord(filePath string, blocks []*block, w io.StringWriter) error
// Loop over functions
// FNDA: stats,name ?

// Loop over lines
total := 0
covered := 0

Expand All @@ -123,9 +122,6 @@ func writeLcovRecord(filePath string, blocks []*block, w io.StringWriter) error
for _, b := range blocks {
// For each line in a block we add an lcov entry and count the lines.
for i := b.startLine; i <= b.endLine; i++ {
if b.covered < 1 {
continue
}
coverMap[i] += b.covered
}
}
Expand All @@ -135,9 +131,13 @@ func writeLcovRecord(filePath string, blocks []*block, w io.StringWriter) error
for _, line := range lines {
err = writer(err, "DA:"+strconv.Itoa(line)+","+strconv.Itoa(coverMap[line])+"\n")
total++
covered += coverMap[line]
if coverMap[line] > 0 {
covered++
}
}

// LH:<number of lines with a non-zero execution count>
// LF:<number of instrumented lines>
err = writer(err, "LF:"+strconv.Itoa(total)+"\n")
err = writer(err, "LH:"+strconv.Itoa(covered)+"\n")

Expand Down
5 changes: 3 additions & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@ SF:main.go
DA:6,1
DA:7,1
DA:8,1
DA:9,0
DA:10,2
DA:11,2
LF:5
LH:7
LF:6
LH:5
end_of_record
`
assert.NoError(t, err)
Expand Down
3 changes: 2 additions & 1 deletion testdata/coverage_expected.lcov
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ DA:46,1
DA:47,1
DA:48,1
DA:49,1
DA:50,0
DA:58,1
LF:6
LF:7
LH:6
end_of_record

0 comments on commit 01d5e75

Please sign in to comment.