diff --git a/src/cargo.rs b/src/cargo.rs index f12b5802..256a81e0 100644 --- a/src/cargo.rs +++ b/src/cargo.rs @@ -26,7 +26,7 @@ pub fn run_cargo( let start = Instant::now(); let argv = cargo_argv(build_dir.path(), packages, phase, options); let env = vec![ - ("CARGO_ENCODED_RUSTFLAGS".to_owned(), rustflags()), + ("CARGO_ENCODED_RUSTFLAGS".to_owned(), rustflags(options)), // The tests might use Insta , and we don't want it to write // updates to the source tree, and we *certainly* don't want it to write // updates and then let the test pass. @@ -140,8 +140,9 @@ fn cargo_argv( /// /// See /// -fn rustflags() -> String { - let rustflags: Vec = if let Some(rustflags) = env::var_os("CARGO_ENCODED_RUSTFLAGS") { +fn rustflags(options: &Options) -> String { + let mut rustflags: Vec = if let Some(rustflags) = env::var_os("CARGO_ENCODED_RUSTFLAGS") + { rustflags .to_str() .expect("CARGO_ENCODED_RUSTFLAGS is not valid UTF-8") @@ -162,7 +163,9 @@ fn rustflags() -> String { // TODO: build.rustflags config value. Vec::new() }; - // rustflags.push("--cap-lints=allow".to_owned()); + if options.cap_lints { + rustflags.push("--cap-lints=warn".to_owned()); + } // debug!("adjusted rustflags: {:?}", rustflags); rustflags.join("\x1f") } @@ -290,6 +293,17 @@ mod test { ); } + #[test] + fn cap_lints_passed_to_cargo() { + let args = Args::try_parse_from(["mutants", "--cap-lints=true"].as_slice()).unwrap(); + let options = Options::from_args(&args).unwrap(); + let build_dir = Utf8Path::new("/tmp/buildXYZ"); + assert_eq!( + cargo_argv(build_dir, None, Phase::Check, &options)[1..], + ["check", "--tests", "--workspace",] + ); + } + #[test] fn feature_args_passed_to_cargo() { let args = Args::try_parse_from( @@ -315,21 +329,34 @@ mod test { fn rustflags_with_no_environment_variables() { env::remove_var("RUSTFLAGS"); env::remove_var("CARGO_ENCODED_RUSTFLAGS"); - assert_eq!(rustflags(), ""); + assert_eq!( + rustflags(&Options { + cap_lints: true, + ..Default::default() + }), + "--cap-lints=warn" + ); } #[test] fn rustflags_added_to_existing_encoded_rustflags() { env::set_var("RUSTFLAGS", "--something\x1f--else"); env::remove_var("CARGO_ENCODED_RUSTFLAGS"); - assert_eq!(rustflags(), "--something\x1f--else"); + let options = Options { + cap_lints: true, + ..Default::default() + }; + assert_eq!(rustflags(&options), "--something\x1f--else\x1f--cap-lints=warn"); } #[test] fn rustflags_added_to_existing_rustflags() { env::set_var("RUSTFLAGS", "-Dwarnings"); env::remove_var("CARGO_ENCODED_RUSTFLAGS"); - assert_eq!(rustflags(), "-Dwarnings"); + assert_eq!(rustflags(&Options { + cap_lints: true, + ..Default::default() + }), "-Dwarnings\x1f--cap-lints=warn"); } } } diff --git a/src/main.rs b/src/main.rs index f25cf4e5..ac6ce962 100644 --- a/src/main.rs +++ b/src/main.rs @@ -117,6 +117,10 @@ pub struct Args { #[arg(long, value_enum, default_value_t = BaselineStrategy::Run, help_heading = "Execution")] baseline: BaselineStrategy, + /// Turn off all rustc lints, so that denied warnings won't make mutants unviable. + #[arg(long, action = ArgAction::Set, default_value_t = false, help_heading = "Build")] + cap_lints: bool, + /// Print mutants that were caught by tests. #[arg(long, short = 'v', help_heading = "Output")] caught: bool, diff --git a/src/options.rs b/src/options.rs index 6902eccd..34422e39 100644 --- a/src/options.rs +++ b/src/options.rs @@ -24,6 +24,9 @@ pub struct Options { /// Run tests in an unmutated tree? pub baseline: BaselineStrategy, + /// Turn off all lints. + pub cap_lints: bool, + /// Don't run the tests, just see if each mutant builds. pub check_only: bool, @@ -196,6 +199,7 @@ impl Options { &config.additional_cargo_test_args, ), baseline: args.baseline, + cap_lints: args.cap_lints, check_only: args.check, colors: args.colors, emit_json: args.json,