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

coverage: Ignore lines that can't be covered #18800

Merged
merged 2 commits into from
Apr 18, 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
17 changes: 10 additions & 7 deletions misc/python/materialize/cli/ci_coverage_pr_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
import subprocess
import sys
from collections import OrderedDict
from typing import Dict, List
from typing import Dict, List, Optional

import junit_xml

from materialize import ROOT, ci_util

Coverage = Dict[str, OrderedDict[int, int]]
# None value indicates that this line is interesting, but we don't know yet if
# it can actually be covered. Int values indicate that the line can be covered
# and how often is has been covered.
Coverage = Dict[str, OrderedDict[int, Optional[int]]]
SOURCE_RE = re.compile(
"^/var/lib/buildkite-agent/builds/buildkite-.*/materialize/coverage/(.*$)"
)
Expand Down Expand Up @@ -47,12 +50,12 @@ def find_modified_lines() -> Coverage:
line = line_raw.decode("utf-8")
# +++ b/src/adapter/src/coord/command_handler.rs
if line.startswith("+++"):
file = line.removeprefix("+++ b/")
if not line.endswith(".rs"):
continue
file = line.removeprefix("+++ b/")
coverage[file] = OrderedDict()
# @@ -641,7 +640,6 @@ impl Coordinator {
elif line.startswith("@@ ") and file:
elif line.startswith("@@ ") and file in coverage:
# We only care about the second value ("+640,6" in the example),
# which contains the line number and length of the modified block
# in new code state.
Expand All @@ -63,7 +66,7 @@ def find_modified_lines() -> Coverage:
start = int(parts)
length = 1
for line_nr in range(start, start + length):
coverage[file][line_nr] = 0
coverage[file][line_nr] = None
return coverage


Expand Down Expand Up @@ -92,7 +95,7 @@ def mark_covered_lines(lcov_file: str, coverage: Coverage) -> None:
line_nr = int(line_str)
hit = int(hit_str) if hit_str.isnumeric() else int(float(hit_str))
if line_nr in coverage[file]:
coverage[file][line_nr] += hit
coverage[file][line_nr] = (coverage[file][line_nr] or 0) + hit


def get_report(coverage: Coverage) -> str:
Expand All @@ -106,7 +109,7 @@ def get_report(coverage: Coverage) -> str:
content = f.readlines()
f.seek(0)
for i, line in enumerate(content):
if i + 1 not in lines or lines[i + 1] > 0:
if lines.get(i + 1) != 0:
f.write(line)
f.truncate()

Expand Down