use .github/common.nu run-cmd
# Run the test suite
#
# Requires the following installed:
# - cargo-llvm-cov
# - cargo-nextest
export def "nur test" [
--clean (-c) # Purge previous test artifacts. Use to refresh coverage data.
--profile (-p): string = 'default' # The profile defined in .config/nextest.toml
] {
if $clean {
run-cmd cargo llvm-cov clean
}
let cmd = [
cargo
llvm-cov
--no-report
--features
"test-skip-wait-for-rate-limit,file-changes"
nextest
--color
always
--profile
$profile
]
run-cmd ...$cmd
}
# Generate detailed coverage report
#
# Pass "--open" to load the built report in your browser
# Requires cargo-llvm-cov installed.
export def --wrapped "nur test llvm-cov" [
...args: string # Additional arguments for `llvm-cov report --html`.
] {
run-cmd cargo llvm-cov report --html ...$args
}
# Generate lcov.info
#
# Useful for codecov uploads or VSCode extensions like "Coverage Gutters".
export def "nur test lcov" [] {
run-cmd cargo llvm-cov report --lcov --output-path lcov.info
}
# Run examples in doc comments as unit tests.
export def "nur test docs" [] {
run-cmd cargo test --doc --features "file-changes"
}
# Rust API docs
export def "nur docs" [
--open (-o) # Open the built docs in your browser
] {
mut cmd = [cargo doc --no-deps --lib --all-features]
if $open {
$cmd = $cmd | append '--open'
}
run-cmd ...$cmd
}
# Run clippy and rustfmt (on packages only)
export def "nur lint" [
--check (-c) # Check only, do not apply fixes
] {
let clippy_args = [cargo, clippy, --features, file-changes]
if $check {
run-cmd ...$clippy_args -- -D warnings
run-cmd cargo fmt -- --check
} else {
run-cmd ...$clippy_args --fix --allow-dirty --allow-staged
run-cmd cargo fmt
}
}
# Run pre-commit hooks manually.
#
# Requires `uv` installed.
export def "nur pre-commit" [
--changes-only (-c), # only run pre-commit on changed files (default is all files)
--upgrade (-u), # upgrade pre-commit hooks defined in the .pre-commit-config.yaml
] {
if $upgrade {
run-cmd uvx pre-commit autoupdate
}
mut args = [pre-commit, run]
if (not $changes_only) {
$args = $args | append [--all-files]
}
run-cmd ...[uvx, ...$args]
}