Resolve Swift coverage regions through each function's filenames.

llvm-cov region[5] indexes that function's filenames, not unit["files"].
On Apple LLVM 21 those orders differ, so the span covering Place.swift line 5
was stored on test_entry_point.swift and the return stayed uncovered.

Proved by tests/fixtures/swift/function-filenames.json, which failed before
the fix (Place.swift received (1, 1, 1) instead of (4, 5, 1)). 226 pytest
tests passed. crapper worst CRAP on coverage.py is 9.0. dryer found no
candidates at 0.8 in coverage.py. mutator on coverage.py: 237 killed,
0 survived, 0 uncovered.

Co-authored-by: Robert C. Martin <[email protected]>
This commit is contained in:
Cursor Agent
2026-11-26 03:21:08 +00:00
co-authored by Robert C. Martin
parent 127ed34454
commit 53865e4a31
5 changed files with 308 additions and 9 deletions
+17
View File
@@ -164,6 +164,23 @@ def test_a_shorter_file_does_not_take_a_longer_files_coverage():
assert bundle.percent_for(long) == 100.0
def test_an_unrelated_longer_source_does_not_block_a_suffix_match(tmp_path):
body = "package demo\nfunc Place() int { return 1 }\n"
covered = tmp_path / "pkg" / "app.go"
other = tmp_path / "other" / "long" / "name.go"
covered.parent.mkdir(parents=True)
other.parent.mkdir(parents=True)
covered.write_text(body, encoding="utf-8")
other.write_text(body, encoding="utf-8")
bundle = CoverageBundle(
go_profile=parse_go_profile("mode: set\nproj/src/pkg/app.go:1.1,2.2 1 1\n")
)
entries = analyze_files([covered, other], tmp_path, bundle)
by_path = {entry.path: entry.coverage for entry in entries}
assert by_path["pkg/app.go"] == 100.0
assert by_path["other/long/name.go"] == 0.0
def test_an_equal_report_key_blocks_a_longer_file():
bundle = CoverageBundle(
go_profile=parse_go_profile("mode: set\n/data/board.go:1.1,2.2 1 1\n")