Skip to content

Commit

Permalink
fix: lcov report respects exclude configs (#1685)
Browse files Browse the repository at this point in the history
  • Loading branch information
tingilee authored Sep 29, 2023
1 parent afa7559 commit 37e1214
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion coverage/lcovreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ def get_lcov(self, fr: FileReporter, analysis: Analysis, outfile: IO[str]) -> No
outfile.write("TN:\n")
outfile.write(f"SF:{fr.relative_filename()}\n")
source_lines = fr.source().splitlines()

sorted_excluded = sorted(analysis.excluded)
for covered in sorted(analysis.executed):
if covered in sorted_excluded:
# Do not report excluded as executed
continue
# Note: Coverage.py currently only supports checking *if* a line
# has been executed, not how many times, so we set this to 1 for
# nice output even if it's technically incorrect.
Expand All @@ -82,6 +85,9 @@ def get_lcov(self, fr: FileReporter, analysis: Analysis, outfile: IO[str]) -> No
outfile.write(f"DA:{covered},1,{line_hash(line)}\n")

for missed in sorted(analysis.missing):
if missed in sorted_excluded:
# Do not report excluded as missing
continue
assert source_lines
line = source_lines[missed-1]
outfile.write(f"DA:{missed},0,{line_hash(line)}\n")
Expand Down

0 comments on commit 37e1214

Please sign in to comment.