From 38ac1a8865d329e088acca75b0557a172e6a5da1 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 22 Jan 2024 07:39:25 -0800 Subject: [PATCH] List own-mutants from in-tree config Concretely, this excludes console.rs, which is excluded in the config --- .cargo/mutants.toml | 2 +- ..._expected_mutants_for_own_source_tree.snap | 122 ------------------ src/visit.rs | 13 +- 3 files changed, 9 insertions(+), 128 deletions(-) diff --git a/.cargo/mutants.toml b/.cargo/mutants.toml index 3455e814..31bc768a 100644 --- a/.cargo/mutants.toml +++ b/.cargo/mutants.toml @@ -1,4 +1,4 @@ # cargo-mutants configuration -error_values = ["::anyhow::anyhow!(\"mutated\")"] +error_values = ["::anyhow::anyhow!(\"mutated!\")"] exclude_globs = ["src/console.rs"] diff --git a/src/snapshots/cargo_mutants__visit__test__expected_mutants_for_own_source_tree.snap b/src/snapshots/cargo_mutants__visit__test__expected_mutants_for_own_source_tree.snap index 51fc1918..d78eb9e5 100644 --- a/src/snapshots/cargo_mutants__visit__test__expected_mutants_for_own_source_tree.snap +++ b/src/snapshots/cargo_mutants__visit__test__expected_mutants_for_own_source_tree.snap @@ -25,128 +25,6 @@ src/config.rs: replace Config::read_file -> Result with Ok(Default::defa src/config.rs: replace Config::read_file -> Result with Err(::anyhow::anyhow!("mutated!")) src/config.rs: replace Config::read_tree_config -> Result with Ok(Default::default()) src/config.rs: replace Config::read_tree_config -> Result with Err(::anyhow::anyhow!("mutated!")) -src/console.rs: replace Console::walk_tree_start with () -src/console.rs: replace Console::walk_tree_update with () -src/console.rs: replace Console::walk_tree_done with () -src/console.rs: replace Console::scenario_started -> Result<()> with Ok(()) -src/console.rs: replace Console::scenario_started -> Result<()> with Err(::anyhow::anyhow!("mutated!")) -src/console.rs: replace Console::scenario_finished with () -src/console.rs: replace += with -= in Console::scenario_finished -src/console.rs: replace += with *= in Console::scenario_finished -src/console.rs: replace += with -= in Console::scenario_finished -src/console.rs: replace += with *= in Console::scenario_finished -src/console.rs: replace += with -= in Console::scenario_finished -src/console.rs: replace += with *= in Console::scenario_finished -src/console.rs: replace += with -= in Console::scenario_finished -src/console.rs: replace += with *= in Console::scenario_finished -src/console.rs: replace += with -= in Console::scenario_finished -src/console.rs: replace += with *= in Console::scenario_finished -src/console.rs: replace += with -= in Console::scenario_finished -src/console.rs: replace += with *= in Console::scenario_finished -src/console.rs: replace += with -= in Console::scenario_finished -src/console.rs: replace += with *= in Console::scenario_finished -src/console.rs: replace || with && in Console::scenario_finished -src/console.rs: replace && with || in Console::scenario_finished -src/console.rs: replace && with || in Console::scenario_finished -src/console.rs: replace && with || in Console::scenario_finished -src/console.rs: replace || with && in Console::scenario_finished -src/console.rs: replace Console::start_copy with () -src/console.rs: replace Console::finish_copy with () -src/console.rs: replace Console::copy_progress with () -src/console.rs: replace Console::discovered_mutants with () -src/console.rs: replace Console::start_testing_mutants with () -src/console.rs: replace Console::scenario_phase_started with () -src/console.rs: replace Console::scenario_phase_finished with () -src/console.rs: replace Console::lab_finished with () -src/console.rs: replace Console::clear with () -src/console.rs: replace Console::message with () -src/console.rs: replace Console::tick with () -src/console.rs: replace Console::make_terminal_writer -> TerminalWriter with Default::default() -src/console.rs: replace Console::make_debug_log_writer -> DebugLogWriter with Default::default() -src/console.rs: replace Console::set_debug_log with () -src/console.rs: replace Console::setup_global_trace -> Result<()> with Ok(()) -src/console.rs: replace Console::setup_global_trace -> Result<()> with Err(::anyhow::anyhow!("mutated!")) -src/console.rs: replace ::make_writer -> Self::Writer with Default::default() -src/console.rs: replace ::write -> std::io::Result with Ok(0) -src/console.rs: replace ::write -> std::io::Result with Ok(1) -src/console.rs: replace ::write -> std::io::Result with Err(::anyhow::anyhow!("mutated!")) -src/console.rs: replace ::flush -> std::io::Result<()> with Err(::anyhow::anyhow!("mutated!")) -src/console.rs: replace ::make_writer -> Self::Writer with Default::default() -src/console.rs: replace ::write -> io::Result with Ok(0) -src/console.rs: replace ::write -> io::Result with Ok(1) -src/console.rs: replace ::write -> io::Result with Err(::anyhow::anyhow!("mutated!")) -src/console.rs: replace ::flush -> io::Result<()> with Ok(()) -src/console.rs: replace ::flush -> io::Result<()> with Err(::anyhow::anyhow!("mutated!")) -src/console.rs: replace ::render -> String with String::new() -src/console.rs: replace ::render -> String with "xyzzy".into() -src/console.rs: replace += with -= in ::render -src/console.rs: replace += with *= in ::render -src/console.rs: replace > with == in ::render -src/console.rs: replace > with < in ::render -src/console.rs: replace > with == in ::render -src/console.rs: replace > with < in ::render -src/console.rs: replace > with == in ::render -src/console.rs: replace > with < in ::render -src/console.rs: replace > with == in ::render -src/console.rs: replace > with < in ::render -src/console.rs: replace > with == in ::render -src/console.rs: replace > with < in ::render -src/console.rs: replace - with + in ::render -src/console.rs: replace - with / in ::render -src/console.rs: replace / with % in ::render -src/console.rs: replace / with * in ::render -src/console.rs: replace * with + in ::render -src/console.rs: replace * with / in ::render -src/console.rs: replace > with == in ::render -src/console.rs: replace > with < in ::render -src/console.rs: replace * with + in ::render -src/console.rs: replace * with / in ::render -src/console.rs: replace / with % in ::render -src/console.rs: replace / with * in ::render -src/console.rs: replace + with - in ::render -src/console.rs: replace + with * in ::render -src/console.rs: replace LabModel::find_scenario_mut -> &mut ScenarioModel with Box::leak(Box::new(Default::default())) -src/console.rs: replace == with != in LabModel::find_scenario_mut -src/console.rs: replace LabModel::remove_scenario with () -src/console.rs: replace != with == in LabModel::remove_scenario -src/console.rs: replace ::render -> String with String::new() -src/console.rs: replace ::render -> String with "xyzzy".into() -src/console.rs: replace == with != in ::render -src/console.rs: replace ScenarioModel::phase_started with () -src/console.rs: replace ScenarioModel::phase_finished with () -src/console.rs: replace ::render -> String with String::new() -src/console.rs: replace ::render -> String with "xyzzy".into() -src/console.rs: replace CopyModel::bytes_copied with () -src/console.rs: replace ::render -> String with String::new() -src/console.rs: replace ::render -> String with "xyzzy".into() -src/console.rs: replace nutmeg_options -> nutmeg::Options with Default::default() -src/console.rs: replace style_outcome -> StyledObject<&'static str> with StyledObject::new() -src/console.rs: replace style_outcome -> StyledObject<&'static str> with StyledObject::from_iter([""]) -src/console.rs: replace style_outcome -> StyledObject<&'static str> with StyledObject::new("") -src/console.rs: replace style_outcome -> StyledObject<&'static str> with StyledObject::from("") -src/console.rs: replace style_outcome -> StyledObject<&'static str> with StyledObject::from_iter(["xyzzy"]) -src/console.rs: replace style_outcome -> StyledObject<&'static str> with StyledObject::new("xyzzy") -src/console.rs: replace style_outcome -> StyledObject<&'static str> with StyledObject::from("xyzzy") -src/console.rs: replace style_secs -> String with String::new() -src/console.rs: replace style_secs -> String with "xyzzy".into() -src/console.rs: replace style_duration -> String with String::new() -src/console.rs: replace style_duration -> String with "xyzzy".into() -src/console.rs: replace format_mb -> String with String::new() -src/console.rs: replace format_mb -> String with "xyzzy".into() -src/console.rs: replace style_mb -> StyledObject with StyledObject::new() -src/console.rs: replace style_mb -> StyledObject with StyledObject::from_iter([String::new()]) -src/console.rs: replace style_mb -> StyledObject with StyledObject::new(String::new()) -src/console.rs: replace style_mb -> StyledObject with StyledObject::from(String::new()) -src/console.rs: replace style_mb -> StyledObject with StyledObject::from_iter(["xyzzy".into()]) -src/console.rs: replace style_mb -> StyledObject with StyledObject::new("xyzzy".into()) -src/console.rs: replace style_mb -> StyledObject with StyledObject::from("xyzzy".into()) -src/console.rs: replace style_scenario -> Cow<'static, str> with Cow::Borrowed("") -src/console.rs: replace style_scenario -> Cow<'static, str> with Cow::Owned("".to_owned()) -src/console.rs: replace style_scenario -> Cow<'static, str> with Cow::Borrowed("xyzzy") -src/console.rs: replace style_scenario -> Cow<'static, str> with Cow::Owned("xyzzy".to_owned()) -src/console.rs: replace plural -> String with String::new() -src/console.rs: replace plural -> String with "xyzzy".into() -src/console.rs: replace == with != in plural src/copy_tree.rs: replace copy_tree -> Result with Ok(Default::default()) src/copy_tree.rs: replace copy_tree -> Result with Err(::anyhow::anyhow!("mutated!")) src/copy_tree.rs: replace += with -= in copy_tree diff --git a/src/visit.rs b/src/visit.rs index 19a4c4aa..85f0ceaf 100644 --- a/src/visit.rs +++ b/src/visit.rs @@ -543,10 +543,13 @@ fn attr_is_mutants_skip(attr: &Attribute) -> bool { #[cfg(test)] mod test { + use std::path::Path; + use indoc::indoc; use itertools::Itertools; use super::*; + use crate::config::Config; use crate::package::Package; use crate::source::SourceFile; @@ -585,11 +588,11 @@ mod test { /// To stop it being too noisy, we use a custom format with no line numbers. #[test] fn expected_mutants_for_own_source_tree() { - let options = Options { - error_values: vec!["::anyhow::anyhow!(\"mutated!\")".to_owned()], - show_line_col: false, - ..Default::default() - }; + let config = Config::read_file(Path::new("./.cargo/mutants.toml")).expect("Read config"); + let args = + Args::try_parse_from(["mutants", "--list", "--line-col=false"]).expect("Parse args"); + let mut options = Options::new(&args, &config).expect("Build options"); + options.colors = false; // TODO: Use a command-line arg. let mut list_output = String::new(); let console = Console::new(); let workspace = Workspace::open(