SPB Git

Repository Public

coverage.sh 2.3 KB 42 lines shellscript

1#!/bin/bash2# ORIX Docs3# File: Scripts/coverage.sh4# Description: Measures line coverage of the engine package by its test targets and writes docs/reports/coverage.json.5#              Each test bundle is exported separately; per source file the best bundle is kept, so the total is a lower bound of the union.6#7# Author: Simon-Pierre Boucher8# Contact: contact@spboucher.ai9set -euo pipefail10cd "$(dirname "$0")/.."11SCRATCH="${ORIX_COV_SCRATCH:-/tmp/orixdocs-cov}"12[[ -n "${ORIX_COV_REUSE:-}" ]] || (cd Packages/ORIXDocsKit && swift test --scratch-path "$SCRATCH" --no-parallel --enable-code-coverage >/dev/null 2>&1) || echo "warning: some tests failed" >&213PROF="$SCRATCH/out/Products/Debug/codecov/default.profdata"14[[ -f "$PROF" ]] || PROF="$(find "$SCRATCH" -name default.profdata | head -1)"15mkdir -p build/cov16for b in "$SCRATCH"/out/Products/Debug/*.xctest; do17  n="$(basename "$b" .xctest)"18  xcrun llvm-cov export -summary-only -instr-profile "$PROF" "$b/Contents/MacOS/$n" > "build/cov/$n.json" 2>/dev/null || true19done20/usr/bin/python3 - <<'PY'21import json, glob, collections22best = {}23for path in glob.glob("build/cov/*.json"):24    try: d = json.load(open(path))25    except Exception: continue26    for f in d["data"][0]["files"]:27        n = f["filename"]28        if "/ORIXDocsKit/Sources/" not in n: continue29        rel = n.split("/Sources/")[1]30        if rel.split("/")[0] in ("orixbench", "orixdocs"): continue31        l = f["summary"]["lines"]32        if rel not in best or l["covered"] > best[rel][0]: best[rel] = (l["covered"], l["count"])33tot = collections.defaultdict(lambda: [0, 0])34for rel, (c, n) in best.items(): t = rel.split("/")[0]; tot[t][0] += c; tot[t][1] += n35C = sum(v[0] for v in tot.values()); N = sum(v[1] for v in tot.values())36out = {"engine_line_coverage_percent": round(100 * C / N, 1), "lines": N, "covered": C,37       "by_target": {k: {"percent": round(100 * v[0] / v[1], 1), "lines": v[1]} for k, v in sorted(tot.items())},38       "note": "Line coverage of Packages/ORIXDocsKit/Sources (command-line tools excluded) by the package's test targets; lower bound of the union across test bundles. The application target is exercised by the interaction self-test and is not included."}39json.dump(out, open("docs/reports/coverage.json", "w"), indent=2)40print(json.dumps(out, indent=1))41PY42
Files main
Menu

Theme