Skip to content
Open
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- New: `--target-dir` sets the Cargo target directory for check, build, and test commands ([#407](https://github.com/sourcefrog/cargo-mutants/issues/407)).
- New: `#[mutants::exclude_re("pattern")]` attribute to exclude specific mutations by regex, without disabling all mutations on the function. The attribute can be placed on functions, `impl` blocks, `trait` blocks, modules, files, and on expressions that can carry an attribute (such as `match`, struct literals, call expressions, method calls, and unary expressions). Multiple patterns can be applied. Also supported within `cfg_attr`. Requires the [mutants](https://crates.io/crates/mutants) crate version `0.0.5` or later.
- Fixed: `#[mutants::skip]` (and `#[cfg_attr(..., mutants::skip)]`) is now honoured when placed on `const` and `static` items, including associated constants in `impl` and `trait` blocks. Previously the attribute was silently ignored on these items and operator mutants inside the initializer expression were still generated ([#508](https://github.com/sourcefrog/cargo-mutants/issues/508)).

Expand Down
14 changes: 14 additions & 0 deletions book/src/cargo-args.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ no_default_features = true

When both command line and config options are specified, the command line flags take precedence for boolean options (`all_features` and `no_default_features`), while features from both sources are combined.

## Target directory

Use `--target-dir` to set the Cargo target directory for every check, build, and test invocation:

```shell
cargo mutants --target-dir target/mutants
```

The path is passed to Cargo unchanged. The equivalent configuration-file form is:

```toml
additional_cargo_args = ["--target-dir=target/mutants"]
```

## Arguments to all `cargo` commands

To pass more arguments to every Cargo invocation, use `--cargo-arg`, or the `additional_cargo_args` configuration key.
Expand Down
38 changes: 38 additions & 0 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ fn cargo_argv(packages: &PackageSelection, phase: Phase, options: &Options) -> V
}
}
}
if let Some(target_dir) = &options.target_dir {
cargo_args.push(format!("--target-dir={target_dir}"));
}
cargo_args.push("--verbose".to_string());
match packages {
PackageSelection::All => {
Expand Down Expand Up @@ -365,6 +368,41 @@ mod test {
);
}

#[test]
fn target_dir_is_passed_to_all_cargo_commands() {
let options = Options::from_arg_strs(["mutants", "--target-dir", "target/mutants"]);

assert_eq!(
cargo_argv(&PackageSelection::All, Phase::Check, &options)[1..],
[
"check",
"--tests",
"--target-dir=target/mutants",
"--verbose",
"--workspace",
]
);
assert_eq!(
cargo_argv(&PackageSelection::All, Phase::Build, &options)[1..],
[
"test",
"--no-run",
"--target-dir=target/mutants",
"--verbose",
"--workspace",
]
);
assert_eq!(
cargo_argv(&PackageSelection::All, Phase::Test, &options)[1..],
[
"test",
"--target-dir=target/mutants",
"--verbose",
"--workspace",
]
);
}

#[test]
fn nextest_gets_special_cargo_profile_option() {
let args = Args::try_parse_from(
Expand Down
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ pub struct Args {
#[arg(long, help_heading = "Build")]
profile: Option<String>,

/// Directory for all generated Cargo artifacts.
#[arg(long, help_heading = "Build", value_name = "DIRECTORY")]
target_dir: Option<Utf8PathBuf>,

// Config ============================================================
/// Read configuration from this file instead of .cargo/mutants.toml.
#[arg(
Expand Down
4 changes: 4 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ pub struct Options {
/// Cargo profile.
pub profile: Option<String>,

/// Directory for Cargo build artifacts.
pub target_dir: Option<Utf8PathBuf>,

/// Additional arguments for every cargo invocation.
pub additional_cargo_args: Vec<String>,

Expand Down Expand Up @@ -384,6 +387,7 @@ impl Options {
test_package,
test_timeout: args.timeout.map(Duration::from_secs_f64),
test_timeout_multiplier: args.timeout_multiplier.or(config.timeout_multiplier),
target_dir: args.target_dir.clone(),
};
if let Some(jobs) = options.jobs
&& jobs > 8
Expand Down