Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lcov] Exclude executed lines respected exclude configs #1685

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[lcov] Exclude executed lines respected exclude configs
  • Loading branch information
tingilee authored and nedbat committed Sep 29, 2023
commit 080ce0603d93a678a836bdb9cb58603a130b1eab
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