#!/bin/bash # Run the full Haven test suite and enforce physical source-line coverage. set -euo pipefail REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "${REPO_ROOT}" workdir="$(mktemp -d "${TMPDIR:-/tmp}/haven-coverage.XXXXXX")" cleanup() { trash "${workdir}"; } trap cleanup EXIT swift test --enable-code-coverage binary=".build/debug/Haven" test_profile=".build/debug/codecov/default.profdata" smoke_profile="${workdir}/smoke.profraw" merged_profile="${workdir}/merged.profdata" LLVM_PROFILE_FILE="${smoke_profile}" HAVEN_COVERAGE_SMOKE=1 "${binary}" test -s "${smoke_profile}" xcrun llvm-profdata merge -sparse "${test_profile}" "${smoke_profile}" -o "${merged_profile}" printf '\nLLVM aggregate report (compiler-generated mappings included):\n' xcrun llvm-cov report "${binary}" \ -instr-profile="${merged_profile}" \ --ignore-filename-regex='(Tests|\\.build)' xcrun llvm-cov export "${binary}" \ -instr-profile="${merged_profile}" \ -format=text > "${workdir}/coverage.json" REPO_ROOT="${REPO_ROOT}" COVERAGE_JSON="${workdir}/coverage.json" python3 <<'PY' import json import os from pathlib import Path repo_root = Path(os.environ["REPO_ROOT"]).resolve() repo_prefix = f"{repo_root.as_posix().rstrip('/')}/" coverage = json.loads(Path(os.environ["COVERAGE_JSON"]).read_text()) covered = 0 total = 0 missed = [] for entry in coverage["data"][0]["files"]: source_path = Path(entry["filename"]).resolve() source_text = source_path.as_posix() if not source_text.casefold().startswith(repo_prefix.casefold()): continue relative_path = Path(source_text[len(repo_prefix) :]) if relative_path.parts[:2] != ("Sources", "Haven"): continue source_lines = source_path.read_text().splitlines() line_counts = {} for segment in entry["segments"]: line, _, count, has_count, *_ = segment if has_count: line_counts[line] = max(line_counts.get(line, 0), count) for line, count in sorted(line_counts.items()): if line > len(source_lines): continue text = source_lines[line - 1].strip() if ( not text or text.startswith("//") or text.startswith("/*") or text.startswith("*") or text.startswith("*/") or not any(character.isalnum() for character in text) ): continue total += 1 if count > 0: covered += 1 else: missed.append(f"{relative_path}:{line}: {text}") print(f"\nPhysical repository source lines: {covered}/{total} covered") if missed: print("Uncovered physical source lines:") print("\n".join(missed)) raise SystemExit(1) PY