Something went wrong. Try again.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950#!/usr/bin/env python3"""Report host production-line coverage from cargo llvm-cov's LCOV export.
Inline test modules and dedicated test/support files are excluded. Native adaptercode and defensive error paths remain in the denominator. Each host file mustreach 90%; missing source records are an error, not zero-length successes."""
import argparsefrom pathlib import Path
parser = argparse.ArgumentParser(description=__doc__)parser.add_argument("lcov", type=Path)args = parser.parse_args()root = Path(__file__).resolve().parent.parenthost = root / "crates/core/src/ui/host"sources = [host.with_suffix(".rs"), *sorted(host.glob("*.rs"))]sources = [path for path in sources if path.name != "test_support.rs"]limits = {}for path in sources: lines = path.read_text().splitlines() # Host inline test modules are terminal; a test-only module declaration # elsewhere must not hide production code from the report. limits[path] = next((i + 1 for i, line in enumerate(lines) if line == "mod tests {" and i > 0 and lines[i - 1] == "#[cfg(test)]"), len(lines) + 1)
coverage = {}source = Nonefor line in args.lcov.read_text().splitlines(): if line.startswith("SF:"): source = Path(line[3:]).resolve() if source in limits: coverage.setdefault(source, {}) elif source in limits and line.startswith("DA:"): number, count = map(int, line[3:].split(",")[:2]) if number < limits[source]: coverage[source][number] = coverage[source].get(number, 0) + count
passed = Truetotal = covered = 0for path in sources: counts = coverage.get(path, {}) hits = sum(count > 0 for count in counts.values()) percentage = 100 * hits / len(counts) if counts else 0 print(f"{str(path.relative_to(root)):50} {hits:4}/{len(counts):4} {percentage:6.2f}%") passed &= bool(counts) and percentage >= 90 total += len(counts) covered += hitsprint(f"Total: {covered}/{total} ({100 * covered / total if total else 0:.2f}%)")raise SystemExit(0 if passed else 1)