Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
prefix-key: v0-rust-nightly

- name: Generate code coverage
run: cargo +nightly llvm-cov --all-features --workspace --lcov --output-path lcov.info
run: make coverage

- name: Upload coverage to Codecov
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,20 @@ jobs:
cache-on-failure: "true"
prefix-key: v0-rust-stable

- name: Install cargo-nextest
uses: baptiste0928/cargo-install@b687c656bda5733207e629b50a22bf68974a0305 # v3.3.2
with:
crate: cargo-nextest
locked: true

- name: Check
run: cargo check --workspace --all-targets
run: make check

- name: Clippy
run: cargo clippy --workspace --all-targets -- -D warnings
run: make clippy

- name: Test
run: cargo test --workspace
run: make test

check-publish:
runs-on: ubuntu-latest
Expand Down
22 changes: 14 additions & 8 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ cargo run -p plotnik-cli -- debug -q '(function_declaration) @fn' -s app.ts -l t
## CLI commands

- IMPORTANT: the `debug` is your first tool you should use to test your changes
- Run tests: `cargo nextest run --hide-progress-bar --status-level none --failure-output final`
- Run tests: `make test`
- We use snapshot testing (`insta`) heavily
- Accept snapshots: `cargo insta accept`
- Accept snapshots: `make snapshots`

## Test structure

Expand Down Expand Up @@ -239,17 +239,23 @@ fn error_case() {

## Coverage

Uses `cargo-llvm-cov`, already installed.
Uses `cargo-llvm-cov` (already installed)

Find uncovered lines per file:

```sh
cargo llvm-cov --package plotnik-lib --text --show-missing-lines 2>/dev/null | grep '\.rs: [0-9]'
$ make coverage-lines | grep recursion
crates/plotnik-lib/src/query/recursion.rs: 78, 210, 214, ...
```

### `invariants.rs`

- Contains functions and `impl` blocks for invariant check functionality
- Each function panics on invariant violation, it may or may not return the value
- When returning value, the name is `ensure_something(...)`, where something is related to return value
- When there is no return value, the name is `assert_something(...)` and something is related to function arguments
- The goal of this file is to exclude coverage of the unreachable code branches
- It contains functions and `impl` blocks for invariant check functionality
- Each function panics on invariant violation
- The naming convention: `ensure_something(...)`, where something refers the return value
- It doesn't make sense to put the `panic!(...)`, `assert!()` or `.expect()` because they don't cause coverage problems:
- `panic!()` usually is called in catch-all `match` branches
- eventually we extract the whole `match` to the `invariants.rs`, for well-established code
- `assert!()` is coverage-friendly alternative for `if condition { panic!(...) }`
- `.expect()` is useful for unwrapping `Result`/`Option` values
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.PHONY: check clippy test snapshots coverage coverage-lines coverage clean

check:
@cargo check --workspace --all-targets

clippy:
@cargo clippy --workspace --all-targets -- -D warnings

test:
@cargo nextest run --no-fail-fast --hide-progress-bar --status-level none --failure-output final

snapshots:
@cargo insta accept

coverage-lines:
@cargo llvm-cov --package plotnik-lib --text --show-missing-lines 2>/dev/null | grep '\.rs: [0-9]' | sed 's|.*/crates/|crates/|'

coverage:
@cargo +nightly llvm-cov --all-features --workspace --lcov --output-path lcov.info

fmt:
@cargo fmt --quiet
@npx -y prettier --list-different --write .

clean:
@cargo clean