mirror of
https://github.com/ankitects/anki.git
synced 2026-06-10 08:29:21 -04:00
## Linked issue Closes #4839 ## Summary / motivation Adds `cargo-llvm-cov`-based test coverage for the full Rust workspace. Introduces `just test-rust --coverage` and `just test-rust --coverage --html`, and wires Rust into the `just test --coverage` umbrella. `cargo-llvm-cov` is installed on demand into `out/bin/` to avoid polluting the global cargo install. The `llvm-tools-preview` rustup component is now installed in CI so the tool can instrument binaries. ## How to test (required) ```sh # Existing behavior unchanged just test-rust # Terminal summary just test-rust --coverage # Terminal summary + HTML report under out/coverage/rust/html/ just test-rust --coverage --html # Umbrella (Rust + Python) just test --coverage just test --coverage --html ``` Note: first run of `--coverage` will install `cargo-llvm-cov` into `out/bin/` (~30s). Subsequent runs skip the install step. ### Checklist - [x] I ran `./ninja check` or an equivalent relevant check locally. ### Details - `cargo-llvm-cov` pinned at `0.8.4`, installed into `out/bin/` via `cargo install --root out`. - `--workspace --locked` measures all crates and respects the lockfile. - `llvm-tools-preview` added to `setup-anki` action so CI can instrument Rust binaries. - Coverage runs are slower than plain `just test-rust` because `cargo-llvm-cov` rebuilds with instrumentation — this is expected. ## Before / after behavior Before: no `just test-rust`, no Rust coverage support. After: `just test-rust` runs Rust tests via ninja; `just test-rust --coverage` runs them with `cargo-llvm-cov` --------- Co-authored-by: Abdo <abdo@abdnh.net>
19 lines
576 B
Bash
Executable File
19 lines
576 B
Bash
Executable File
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
html="$1"
|
|
|
|
outdir="out/coverage/rust"
|
|
LLVMCOVPATH="out/bin"
|
|
|
|
mkdir -p $outdir $LLVMCOVPATH
|
|
test -x $LLVMCOVPATH/cargo-llvm-cov || cargo install cargo-llvm-cov --version 0.8.4 --locked --root out
|
|
ANKI_TEST_MODE=1 $LLVMCOVPATH/cargo-llvm-cov llvm-cov --workspace --locked --json --summary-only \
|
|
--output-path $outdir/coverage-summary.json --fail-under-lines 60
|
|
|
|
if [ "$html" = "--html" ]; then
|
|
ANKI_TEST_MODE=1 $LLVMCOVPATH/cargo-llvm-cov llvm-cov report --html --output-dir $outdir/html
|
|
echo "Rust coverage report: $outdir/html/index.html"
|
|
fi
|