mirror of
https://github.com/unclebob/mutator.git
synced 2026-11-26 18:58:50 +00:00
Read Swift coverage from the reports crapper already parses.
llvm-cov JSON and xccov JSON land in target/coverage/swift. crapper turns those into regions or function summaries. A region with a hit marks that line covered. An xccov summary has no lines, so the function line is covered when the summary's covered count is above zero. A file missing from the report stays uncovered and is not run. Proved by tests/test_coverage.py, which failed first because a Swift file with a report still returned no lines, and by a scan that marks an unhit line uncovered. The reports are the same JSON shapes crapper reads; mutator does not parse them itself. Co-authored-by: Robert C. Martin <[email protected]>
This commit is contained in:
co-authored by
Robert C. Martin
parent
7c72d9deba
commit
3f6dc5bb7c
@@ -330,6 +330,35 @@ def test_a_run_invokes_swift_test_and_xcodebuild_with_the_destination(tmp_path,
|
||||
assert destination in xcode_text.splitlines()
|
||||
|
||||
|
||||
def test_scan_marks_a_swift_line_uncovered_when_llvm_cov_did_not_hit_it(tmp_path, capsys):
|
||||
import json
|
||||
|
||||
source = tmp_path / "Sources" / "Demo" / "Box.swift"
|
||||
source.parent.mkdir(parents=True)
|
||||
source.write_text("func place(x: Int) -> Int {\n return x > 0 ? x : 0\n}\n", encoding="utf-8")
|
||||
report = tmp_path / "target" / "coverage" / "swift" / "llvm-cov.json"
|
||||
report.parent.mkdir(parents=True)
|
||||
report.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"type": "llvm.coverage.json.export",
|
||||
"data": [
|
||||
{
|
||||
"files": [{"filename": str(source)}],
|
||||
"functions": [{"regions": [[1, 1, 1, 2, 1, 0, 0, 0]]}],
|
||||
}
|
||||
],
|
||||
}
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
code = run(["--scan", "--use-existing-coverage", "--root", str(tmp_path), str(source)])
|
||||
captured = capsys.readouterr()
|
||||
assert code == 0
|
||||
assert "uncovered" in captured.out
|
||||
assert "x > 0 -> !(x > 0)" in captured.out or "> -> >=" in captured.out
|
||||
|
||||
|
||||
def test_a_swift_run_records_killed_and_survived_on_the_crapper_namespace(tmp_path, capsys):
|
||||
relative = "Sources/Demo/Place.swift"
|
||||
path = tmp_path / relative
|
||||
|
||||
Reference in New Issue
Block a user