This extension provides rust_mutation_test, a rule that mutation-tests a
rust_library by compiling and running tests against automatically-mutated
source variants.
Primary API docs are in defs.bzl and generated site docs
(rust_mutation.md in the rules_rust docs book).
rust_mutation_test:
rust_library.collect_inputs + construct_arguments).cargo-mutants JSON output.CAUGHT or SURVIVED.Status meanings:
CAUGHT: mutant fails to compile or tests fail.SURVIVED: mutant compiles and tests pass.Current behavior:
allow_survivors = True to report survivors without failing the target.No mutations generated..bazel_dep(name = "rules_rust_mutants", version = "{SEE_RELEASE_NOTES}")
load("@rules_rust_mutants//:repositories.bzl", "rust_mutation_dependencies")
rust_mutation_dependencies()
load("@rules_rust//rust:defs.bzl", "rust_library")
load("@rules_rust_mutants//:defs.bzl", "rust_mutation_test")
rust_library(
name = "my_lib",
srcs = ["lib.rs"],
edition = "2021",
)
rust_mutation_test(
name = "my_lib_mutation_test",
crate = ":my_lib",
)
Run:
bazel test //:my_lib_mutation_test --test_output=all
Mutation enumeration uses
cargo mutants --list --json --diff --Zmutate-file ....
mutants_config = "path/to/mutants.toml" is forwarded as
cargo mutants --config <path>.
allow_survivors = True changes survivor handling:
False): if any mutant survives, the Bazel test fails.True: survivors are still reported, but the Bazel test exits successfully.cargo-mutants binary from source.cargo-mutants internally invokes Cargo; the runner provides Cargo from the
active Rust toolchain.Running baseline compile+test...
Generated 5 mutants
mutant_0_src/lib.rs_binop - CAUGHT
mutant_1_src/lib.rs_binop - SURVIVED
Mutation Testing Summary
========================
Total: 5 Caught: 4 (80%) Survived: 1 (20%)
For survivors, a unified diff is printed for each surviving mutant.
//:clippy//private:runner_unit_test//test:all0.69.02026-04-01 |