#!/usr/bin/env bash
set -euo pipefail

root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "${root}"

out_dir="${root}/tmp/coverage"
mkdir -p "${out_dir}"

# Generates an HTML coverage report + a single-line summary.
# (llvm-cov doesn't allow --summary-only together with --html, so we do LCOV + HTML.)
exec nix develop --accept-flake-config -c bash -lc "
  set -euo pipefail
  cargo llvm-cov --workspace --lcov --output-path '${out_dir}/coverage.lcov'
  '${root}/scripts/coverage-summary.sh' '${out_dir}/coverage.lcov' | tee '${out_dir}/summary.txt'
  cargo llvm-cov --workspace --html --output-dir '${out_dir}/html'
"
