go-coverage-report icon indicating copy to clipboard operation
go-coverage-report copied to clipboard

Incorrect coverage values when coverage reports have duplicate blocks

Open LanderK-Bondaval opened this issue 7 months ago • 1 comments

I discovered that coverage reports containing duplicate blocks for the same source code segment are parsed incorrectly, resulting in inflated or inaccurate coverage percentages. The current parser counts duplicate blocks multiple times instead of merging or deduplicating them.

This issue can arise from certain Go test configurations or tooling that produce repeated blocks in coverage output.

Impact: The coverage percentage values produced by this action often differ significantly from the "true" value and those reported by go tool cover. For example, in one test case, the action reported ~20% coverage while go tool cover -html showed ~95% coverage. This discrepancy can cause confusion and mistrust of coverage results.

Screenshots

Image Image

Fix I have a PR ready with the fix, including tests and sample coverage files demonstrating the problem.

This fix aligns the parsing logic with how go tool cover handles coverage blocks — it correctly calculates total coverage after profile parsing and block deduplication logic in ParseProfilesFromReader.

Looking forward to feedback and hoping this can be merged to improve coverage accuracy.

Thanks!

LanderK-Bondaval avatar Jun 18 '25 14:06 LanderK-Bondaval

We fixed this by merging the cover lines with this awk:

awk < build/coverprofile.out '$1 != "mode:" { is_filename[$1] = true; counts1[$1]+=$2; counts2[$1]+=$3 } END { for (filename in is_filename) { printf "%s %d %d\n", filename, counts1[filename], counts2[filename]; } }' | sort | sed '1s/^/mode: count\n/' > build/cover.out

SuperSandro2000 avatar Sep 01 '25 11:09 SuperSandro2000