Skip to content

Commit bca685a

Browse files
committed
bot: Assume lines outside the coverage record are uncoverable
It can happen for the last few lines of a file, if they are actually uncoverable. For some reason, they are not considered by instrumentation.
1 parent 4124619 commit bca685a

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

bot/code_coverage_bot/phabricator.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,12 @@ def _build_coverage_map(self, annotate, coverage_record):
9090
# The changeset when it was introduced.
9191
orig_changeset = data["node"]
9292

93-
if lineno < len(coverage_record):
94-
key = (orig_changeset, orig_line)
95-
coverage_map[key] = coverage_record[lineno]
93+
key = (orig_changeset, orig_line)
94+
# Assume lines outside the coverage record are uncoverable (that happens for the
95+
# last few lines of a file, they are not considered by instrumentation).
96+
coverage_map[key] = (
97+
coverage_record[lineno] if lineno < len(coverage_record) else -1
98+
)
9699

97100
return coverage_map
98101

bot/tests/test_phabricator.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,37 @@ def test_backout_removed_file(mock_secrets, fake_hg_repo):
448448
}
449449

450450

451+
def test_coverable_last_lines(mock_secrets, mock_phabricator, fake_hg_repo):
452+
hg, local, remote = fake_hg_repo
453+
454+
add_file(hg, local, "file", "1\n2\n3\n4\n5\n6\n7\n")
455+
revision = commit(hg, 1)
456+
457+
hg.push(dest=bytes(remote, "ascii"))
458+
459+
copy_pushlog_database(remote, local)
460+
461+
phabricator = PhabricatorUploader(local, revision)
462+
report = covdir_report(
463+
{"source_files": [{"name": "file", "coverage": [None, 0, 1, 1, 1]}]}
464+
)
465+
results = phabricator.generate(report, changesets(local, revision))
466+
467+
assert results == {
468+
revision: {
469+
"revision_id": 1,
470+
"paths": {
471+
"file": {
472+
"coverage": "NUCCCNN",
473+
"lines_added": 4,
474+
"lines_covered": 3,
475+
"lines_unknown": 0,
476+
}
477+
},
478+
}
479+
}
480+
481+
451482
def test_third_party(mock_secrets, fake_hg_repo):
452483
hg, local, remote = fake_hg_repo
453484

0 commit comments

Comments
 (0)