Skip to content

Commit

Permalink
Merge pull request #18800 from def-/pr-coverage-fix
Browse files Browse the repository at this point in the history
coverage: Ignore lines that can't be covered
  • Loading branch information
def- authored Apr 18, 2023
2 parents 85ef9f5 + 2a40d9b commit 8147c0b
Showing 1 changed file with 10 additions and 7 deletions.
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

0 comments on commit 8147c0b

Please sign in to comment.