diff --git a/crates/bough-cli/src/config.rs b/crates/bough-cli/src/config.rs index e1c57d3e..042ce52c 100644 --- a/crates/bough-cli/src/config.rs +++ b/crates/bough-cli/src/config.rs @@ -1995,9 +1995,7 @@ impl PhaseOverrides { let absolute = self.resolve_timeout_absolute(global); let relative_multiplier = self.resolve_timeout_relative(global); let relative = match (relative_multiplier, reference) { - (Some(multiplier), Some(ref_dur)) => { - Some(ref_dur * multiplier as i32) - } + (Some(multiplier), Some(ref_dur)) => Some(ref_dur * multiplier as i32), _ => None, }; match (absolute, relative) { @@ -2212,7 +2210,7 @@ impl crate::render::Render for Config { #[cfg(test)] mod config_render_tests { use super::*; - use crate::render::{TITLE, RESET, Render}; + use crate::render::{RESET, Render, TITLE}; fn fixture() -> Config { let json = r#"{"base_root_dir":".","include":[],"exclude":[],"lang":{},"find":{"number":1,"number_per_file":1,"factors":[]}}"#; diff --git a/crates/bough-cli/src/find_best_mutations.rs b/crates/bough-cli/src/find_best_mutations.rs index 37c9539f..37cb7bcb 100644 --- a/crates/bough-cli/src/find_best_mutations.rs +++ b/crates/bough-cli/src/find_best_mutations.rs @@ -4,12 +4,16 @@ use std::path::PathBuf; use bough_core::{LanguageId, MutationHash, Session, State}; use crate::config::Config; -use crate::render::{BOLD, TITLE, RESET, Render}; +use crate::render::{BOLD, RESET, Render, TITLE}; pub struct FindBestMutations(pub Vec<(MutationHash, State, f64)>); impl FindBestMutations { - pub fn run(session: impl Deref>, lang: Option, file: Option) -> Box { + pub fn run( + session: impl Deref>, + lang: Option, + file: Option, + ) -> Box { let results = session.find_best_mutations().expect("find best mutations"); let filtered: Vec<_> = results .into_iter() @@ -85,7 +89,9 @@ impl Render for FindBestMutations { .map(|(hash, state, score)| { format!( r#"{{"hash":"{}","score":{},"state":{}}}"#, - hash, score, state.json(), + hash, + score, + state.json(), ) }) .collect(); @@ -115,8 +121,7 @@ mod tests { #[test] fn markdown() { - let plain = fixture().markdown() - .replace(TITLE, "").replace(RESET, ""); + let plain = fixture().markdown().replace(TITLE, "").replace(RESET, ""); assert!(plain.starts_with("# Best Mutations\n\n1 selected")); assert!(plain.contains("0.75")); } @@ -130,8 +135,11 @@ mod tests { #[test] fn verbose() { - let plain = fixture().verbose() - .replace(TITLE, "").replace(BOLD, "").replace(RESET, ""); + let plain = fixture() + .verbose() + .replace(TITLE, "") + .replace(BOLD, "") + .replace(RESET, ""); assert!(plain.starts_with("Best Mutations (1 selected)")); assert!(plain.contains("score=0.75")); } @@ -143,5 +151,3 @@ mod tests { assert!(out.contains(r#""score":0.75"#)); } } - - diff --git a/crates/bough-cli/src/main.rs b/crates/bough-cli/src/main.rs index a40c11f5..dd423871 100644 --- a/crates/bough-cli/src/main.rs +++ b/crates/bough-cli/src/main.rs @@ -47,7 +47,9 @@ fn main() { match show { Show::Config => Box::new(cli.config.clone()), - Show::Files { lang: None } => show_all_files::ShowAllFiles::run(session.lock().unwrap()), + Show::Files { lang: None } => { + show_all_files::ShowAllFiles::run(session.lock().unwrap()) + } Show::Files { lang: Some(lang) } => { show_language_files::ShowLanguageFiles::run(session.lock().unwrap(), *lang) @@ -61,7 +63,10 @@ fn main() { Show::Mutations { lang: Some(lang), file: None, - } => show_language_mutations::ShowLanguageMutations::run(session.lock().unwrap(), *lang), + } => show_language_mutations::ShowLanguageMutations::run( + session.lock().unwrap(), + *lang, + ), Show::Mutations { lang: Some(lang), @@ -82,24 +87,31 @@ fn main() { debug!(subcommand = ?step, "executing step command"); match step { - config::Step::TendState => step_tend_state::StepTendState::run(session.lock().unwrap()), - - config::Step::TendWorkspaces => { - step_tend_workspaces::StepTendWorkspaces::run(session.lock().unwrap(), &cli.config) + config::Step::TendState => { + step_tend_state::StepTendState::run(session.lock().unwrap()) } + config::Step::TendWorkspaces => step_tend_workspaces::StepTendWorkspaces::run( + session.lock().unwrap(), + &cli.config, + ), + config::Step::InitWorkspace { workspace_id } => { let guard = session.lock().unwrap(); - let wid = bough_core::WorkspaceId::parse(workspace_id).expect("invalid workspace id"); + let wid = + bough_core::WorkspaceId::parse(workspace_id).expect("invalid workspace id"); let workspace = guard.bind_workspace(&wid).expect("bind workspace"); - step_init_workspace::StepInitWorkspace::run(&workspace, &cli.config, None).expect("init workspace") + step_init_workspace::StepInitWorkspace::run(&workspace, &cli.config, None) + .expect("init workspace") } config::Step::ResetWorkspace { workspace_id } => { let guard = session.lock().unwrap(); - let wid = bough_core::WorkspaceId::parse(workspace_id).expect("invalid workspace id"); + let wid = + bough_core::WorkspaceId::parse(workspace_id).expect("invalid workspace id"); let workspace = guard.bind_workspace(&wid).expect("bind workspace"); - step_reset_workspace::StepResetWorkspace::run(&workspace, &cli.config, None).expect("reset workspace") + step_reset_workspace::StepResetWorkspace::run(&workspace, &cli.config, None) + .expect("reset workspace") } config::Step::ApplyMutation { @@ -107,10 +119,14 @@ fn main() { mutation_hash, } => { let guard = session.lock().unwrap(); - let wid = bough_core::WorkspaceId::parse(workspace_id).expect("invalid workspace id"); - let mutation = guard.resolve_mutation(UnvalidatedHash::new(mutation_hash.to_string())).expect("resolve mutation"); + let wid = + bough_core::WorkspaceId::parse(workspace_id).expect("invalid workspace id"); + let mutation = guard + .resolve_mutation(UnvalidatedHash::new(mutation_hash.to_string())) + .expect("resolve mutation"); let mut workspace = guard.bind_workspace(&wid).expect("bind workspace"); - step_apply_mutation::StepApplyMutation::run(&mut workspace, &mutation).expect("apply mutation") + step_apply_mutation::StepApplyMutation::run(&mut workspace, &mutation) + .expect("apply mutation") } config::Step::UnapplyMutation { @@ -118,9 +134,11 @@ fn main() { mutation_hash: _, } => { let guard = session.lock().unwrap(); - let wid = bough_core::WorkspaceId::parse(workspace_id).expect("invalid workspace id"); + let wid = + bough_core::WorkspaceId::parse(workspace_id).expect("invalid workspace id"); let mut workspace = guard.bind_workspace(&wid).expect("bind workspace"); - step_unapply_mutation::StepUnapplyMutation::run(&mut workspace).expect("unapply mutation") + step_unapply_mutation::StepUnapplyMutation::run(&mut workspace) + .expect("unapply mutation") } config::Step::TestMutation { @@ -128,13 +146,26 @@ fn main() { mutation_hash, } => { let mut guard = session.lock().unwrap(); - let wid = bough_core::WorkspaceId::parse(workspace_id).expect("invalid workspace id"); - let mutation = guard.resolve_mutation(UnvalidatedHash::new(mutation_hash.to_string())).expect("resolve mutation"); + let wid = + bough_core::WorkspaceId::parse(workspace_id).expect("invalid workspace id"); + let mutation = guard + .resolve_mutation(UnvalidatedHash::new(mutation_hash.to_string())) + .expect("resolve mutation"); let mut workspace = guard.bind_workspace(&wid).expect("bind workspace"); - step_apply_mutation::StepApplyMutation::run(&mut workspace, &mutation).expect("apply mutation"); - let result = step_test_mutation::StepTestMutation::run(&workspace, &cli.config, &mutation, None).expect("test mutation"); - step_unapply_mutation::StepUnapplyMutation::run(&mut workspace).expect("unapply mutation"); - guard.set_state(&mutation, result.status_value.clone()).expect("set state"); + step_apply_mutation::StepApplyMutation::run(&mut workspace, &mutation) + .expect("apply mutation"); + let result = step_test_mutation::StepTestMutation::run( + &workspace, + &cli.config, + &mutation, + None, + ) + .expect("test mutation"); + step_unapply_mutation::StepUnapplyMutation::run(&mut workspace) + .expect("unapply mutation"); + guard + .set_state(&mutation, result.status_value.clone()) + .expect("set state"); result } } @@ -142,9 +173,11 @@ fn main() { Command::Run => run::Run::run(Arc::clone(&session), &cli), - Command::Find { ref lang, ref file } => { - find_best_mutations::FindBestMutations::run(session.lock().unwrap(), *lang, file.clone()) - } + Command::Find { ref lang, ref file } => find_best_mutations::FindBestMutations::run( + session.lock().unwrap(), + *lang, + file.clone(), + ), Command::Noop => { info!("starting run"); diff --git a/crates/bough-cli/src/render.rs b/crates/bough-cli/src/render.rs index 59beba2d..cb4a3026 100644 --- a/crates/bough-cli/src/render.rs +++ b/crates/bough-cli/src/render.rs @@ -539,10 +539,9 @@ impl Render for PhaseOutcome { "- Exit: {exit_code}\n- Duration: {:.2}s", duration.as_secs_f64(), ), - PhaseOutcome::TimedOut { duration, .. } => format!( - "- Timed out after {:.2}s", - duration.as_secs_f64(), - ), + PhaseOutcome::TimedOut { duration, .. } => { + format!("- Timed out after {:.2}s", duration.as_secs_f64(),) + } }; format!("{header}{}", phase_stdio_markdown_suffix(self)) } @@ -570,10 +569,9 @@ impl Render for PhaseOutcome { "Exit: {exit_code}\nDuration: {:.2}s", duration.as_secs_f64(), ), - PhaseOutcome::TimedOut { duration, .. } => format!( - "Timed out after {:.2}s", - duration.as_secs_f64(), - ), + PhaseOutcome::TimedOut { duration, .. } => { + format!("Timed out after {:.2}s", duration.as_secs_f64(),) + } }; format!("{header}{}", phase_stdio_verbose_suffix(self)) } diff --git a/crates/bough-cli/src/run.rs b/crates/bough-cli/src/run.rs index 461ec2e2..ee61c80a 100644 --- a/crates/bough-cli/src/run.rs +++ b/crates/bough-cli/src/run.rs @@ -30,7 +30,11 @@ impl Run { let base = guard.base(); let init_duration = match base.run_init(&cli.config, None) { - Ok(bough_core::PhaseOutcome::Completed { exit_code, duration, .. }) => { + Ok(bough_core::PhaseOutcome::Completed { + exit_code, + duration, + .. + }) => { if exit_code != 0 { eprintln!("base init failed (exit {exit_code})"); std::process::exit(1); @@ -49,7 +53,11 @@ impl Run { }; let reset_duration = match base.run_reset(&cli.config, None) { - Ok(bough_core::PhaseOutcome::Completed { exit_code, duration, .. }) => { + Ok(bough_core::PhaseOutcome::Completed { + exit_code, + duration, + .. + }) => { if exit_code != 0 { eprintln!("base reset failed (exit {exit_code})"); std::process::exit(1); @@ -105,8 +113,12 @@ impl Run { ctrlc::set_handler(move || { done_for_handler.store(true, Ordering::SeqCst); eprintln!("\nInterrupted. Waiting for in-flight tests to finish..."); - eprintln!("Repeated Ctrl-C will NOT force-kill — this avoids orphaning test processes."); - eprintln!("If you must kill bough, send SIGKILL and clean up child processes manually."); + eprintln!( + "Repeated Ctrl-C will NOT force-kill — this avoids orphaning test processes." + ); + eprintln!( + "If you must kill bough, send SIGKILL and clean up child processes manually." + ); }) .expect("failed to set ctrl-c handler"); @@ -230,9 +242,8 @@ impl Run { Ok(r) => r, Err(e) => { error!(%workspace_id, err = %e, "test execution failed"); - let _ = step_unapply_mutation::StepUnapplyMutation::run( - &mut workspace, - ); + let _ = + step_unapply_mutation::StepUnapplyMutation::run(&mut workspace); continue; } }; @@ -247,8 +258,7 @@ impl Run { error!(%workspace_id, "mutex poisoned setting state"); break; }; - if let Err(e) = - guard.set_state(&mutation, test_result.status_value.clone()) + if let Err(e) = guard.set_state(&mutation, test_result.status_value.clone()) { error!(%workspace_id, err = ?e, "failed to set state"); } diff --git a/crates/bough-cli/src/show_all_files.rs b/crates/bough-cli/src/show_all_files.rs index dd322558..b6a52c22 100644 --- a/crates/bough-cli/src/show_all_files.rs +++ b/crates/bough-cli/src/show_all_files.rs @@ -5,7 +5,7 @@ use bough_core::{File, Session}; use facet::Facet; use crate::config::Config; -use crate::render::{PATH, RESET, TITLE, Render}; +use crate::render::{PATH, RESET, Render, TITLE}; #[derive(Facet)] pub struct ShowAllFiles(pub Vec); @@ -51,7 +51,11 @@ impl Render for ShowAllFiles { } fn json(&self) -> String { - let items: Vec = self.0.iter().map(|p| format!("\"{}\"", p.display())).collect(); + let items: Vec = self + .0 + .iter() + .map(|p| format!("\"{}\"", p.display())) + .collect(); format!("[{}]", items.join(",")) } } @@ -94,10 +98,7 @@ mod tests { #[test] fn verbose() { - let plain = fixture() - .verbose() - .replace(PATH, "") - .replace(RESET, ""); + let plain = fixture().verbose().replace(PATH, "").replace(RESET, ""); assert_eq!( plain, "\ @@ -108,11 +109,6 @@ src/lib.ts" #[test] fn json() { - assert_eq!( - fixture().json(), - r#"["src/main.ts","src/lib.ts"]"# - ); + assert_eq!(fixture().json(), r#"["src/main.ts","src/lib.ts"]"#); } } - - diff --git a/crates/bough-cli/src/show_all_mutations.rs b/crates/bough-cli/src/show_all_mutations.rs index 998dcd0f..814184ac 100644 --- a/crates/bough-cli/src/show_all_mutations.rs +++ b/crates/bough-cli/src/show_all_mutations.rs @@ -5,7 +5,7 @@ use bough_typed_hash::TypedHashable; use facet::Facet; use crate::config::Config; -use crate::render::{TITLE, RESET, Render, render_table}; +use crate::render::{RESET, Render, TITLE, render_table}; #[derive(Facet)] pub struct ShowAllMutations(pub Vec); @@ -43,11 +43,20 @@ impl Render for ShowAllMutations { } fn terse(&self) -> String { - self.0.iter().map(|s| s.terse()).collect::>().join("\n") + self.0 + .iter() + .map(|s| s.terse()) + .collect::>() + .join("\n") } fn verbose(&self) -> String { - let list = self.0.iter().map(|s| s.verbose()).collect::>().join("\n"); + let list = self + .0 + .iter() + .map(|s| s.verbose()) + .collect::>() + .join("\n"); format!( "{TITLE}All Mutations{RESET} ({} total)\n\n{list}", self.0.len(), @@ -105,5 +114,3 @@ mod tests { assert!(out.ends_with(']')); } } - - diff --git a/crates/bough-cli/src/show_file_mutations.rs b/crates/bough-cli/src/show_file_mutations.rs index af732e58..f142b791 100644 --- a/crates/bough-cli/src/show_file_mutations.rs +++ b/crates/bough-cli/src/show_file_mutations.rs @@ -6,13 +6,17 @@ use bough_typed_hash::TypedHashable; use facet::Facet; use crate::config::Config; -use crate::render::{PATH, TITLE, RESET, Render, render_table}; +use crate::render::{PATH, RESET, Render, TITLE, render_table}; #[derive(Facet)] pub struct ShowFileMutations(pub LanguageId, pub PathBuf, pub Vec); impl ShowFileMutations { - pub fn run(mut session: impl DerefMut>, lang: LanguageId, file: PathBuf) -> Box { + pub fn run( + mut session: impl DerefMut>, + lang: LanguageId, + file: PathBuf, + ) -> Box { session.tend_add_missing_states().expect("tend states"); let base = session.base(); let mutations: Vec<_> = base @@ -20,9 +24,7 @@ impl ShowFileMutations { .collect::, _>>() .expect("mutation scan") .into_iter() - .filter(|m| { - m.mutant().lang() == lang && m.mutant().twig().path() == file.as_path() - }) + .filter(|m| m.mutant().lang() == lang && m.mutant().twig().path() == file.as_path()) .collect(); let states = mutations .into_iter() @@ -50,11 +52,20 @@ impl Render for ShowFileMutations { } fn terse(&self) -> String { - self.2.iter().map(|s| s.terse()).collect::>().join("\n") + self.2 + .iter() + .map(|s| s.terse()) + .collect::>() + .join("\n") } fn verbose(&self) -> String { - let list = self.2.iter().map(|s| s.verbose()).collect::>().join("\n"); + let list = self + .2 + .iter() + .map(|s| s.verbose()) + .collect::>() + .join("\n"); format!( "{TITLE}Mutations in{RESET} {PATH}{}{RESET} ({} total)\n\n{list}", self.1.display(), @@ -99,8 +110,11 @@ mod tests { #[test] fn markdown() { - let plain = fixture().markdown() - .replace(TITLE, "").replace(PATH, "").replace(RESET, ""); + let plain = fixture() + .markdown() + .replace(TITLE, "") + .replace(PATH, "") + .replace(RESET, ""); assert!(plain.starts_with("# Mutations in src/main.ts\n\n1 total")); } @@ -112,8 +126,11 @@ mod tests { #[test] fn verbose() { - let plain = fixture().verbose() - .replace(TITLE, "").replace(PATH, "").replace(RESET, ""); + let plain = fixture() + .verbose() + .replace(TITLE, "") + .replace(PATH, "") + .replace(RESET, ""); assert!(plain.starts_with("Mutations in src/main.ts (1 total)")); } @@ -125,5 +142,3 @@ mod tests { assert!(out.contains(r#""file":"src/main.ts""#)); } } - - diff --git a/crates/bough-cli/src/show_language_files.rs b/crates/bough-cli/src/show_language_files.rs index fd54a1be..c489edc4 100644 --- a/crates/bough-cli/src/show_language_files.rs +++ b/crates/bough-cli/src/show_language_files.rs @@ -5,7 +5,7 @@ use bough_core::{File, LanguageId, Session}; use facet::Facet; use crate::config::Config; -use crate::render::{PATH, RESET, TITLE, Render}; +use crate::render::{PATH, RESET, Render, TITLE}; #[derive(Facet)] pub struct ShowLanguageFiles(pub LanguageId, pub Vec); @@ -56,8 +56,16 @@ impl Render for ShowLanguageFiles { } fn json(&self) -> String { - let paths: Vec = self.1.iter().map(|p| format!("\"{}\"", p.display())).collect(); - format!(r#"{{"lang":{},"files":[{}]}}"#, self.0.json(), paths.join(",")) + let paths: Vec = self + .1 + .iter() + .map(|p| format!("\"{}\"", p.display())) + .collect(); + format!( + r#"{{"lang":{},"files":[{}]}}"#, + self.0.json(), + paths.join(",") + ) } } @@ -68,10 +76,7 @@ mod tests { fn fixture() -> ShowLanguageFiles { ShowLanguageFiles( LanguageId::Typescript, - vec![ - PathBuf::from("src/main.ts"), - PathBuf::from("src/lib.ts"), - ], + vec![PathBuf::from("src/main.ts"), PathBuf::from("src/lib.ts")], ) } @@ -123,5 +128,3 @@ TypeScript ); } } - - diff --git a/crates/bough-cli/src/show_language_mutations.rs b/crates/bough-cli/src/show_language_mutations.rs index 259c7257..9acf3a96 100644 --- a/crates/bough-cli/src/show_language_mutations.rs +++ b/crates/bough-cli/src/show_language_mutations.rs @@ -5,13 +5,16 @@ use bough_typed_hash::TypedHashable; use facet::Facet; use crate::config::Config; -use crate::render::{TITLE, RESET, Render, render_table}; +use crate::render::{RESET, Render, TITLE, render_table}; #[derive(Facet)] pub struct ShowLanguageMutations(pub LanguageId, pub Vec); impl ShowLanguageMutations { - pub fn run(mut session: impl DerefMut>, lang: LanguageId) -> Box { + pub fn run( + mut session: impl DerefMut>, + lang: LanguageId, + ) -> Box { session.tend_add_missing_states().expect("tend states"); let base = session.base(); let mutations: Vec<_> = base @@ -47,11 +50,20 @@ impl Render for ShowLanguageMutations { } fn terse(&self) -> String { - self.1.iter().map(|s| s.terse()).collect::>().join("\n") + self.1 + .iter() + .map(|s| s.terse()) + .collect::>() + .join("\n") } fn verbose(&self) -> String { - let list = self.1.iter().map(|s| s.verbose()).collect::>().join("\n"); + let list = self + .1 + .iter() + .map(|s| s.verbose()) + .collect::>() + .join("\n"); format!( "{TITLE}{} Mutations{RESET} ({} total)\n\n{list}", self.0.verbose(), @@ -86,8 +98,11 @@ mod tests { #[test] fn markdown() { - let plain = fixture().markdown() - .replace(TITLE, "").replace(crate::render::LANG, "").replace(RESET, ""); + let plain = fixture() + .markdown() + .replace(TITLE, "") + .replace(crate::render::LANG, "") + .replace(RESET, ""); assert!(plain.starts_with("# TypeScript Mutations\n\n1 total")); } @@ -98,8 +113,11 @@ mod tests { #[test] fn verbose() { - let plain = fixture().verbose() - .replace(TITLE, "").replace(crate::render::LANG, "").replace(RESET, ""); + let plain = fixture() + .verbose() + .replace(TITLE, "") + .replace(crate::render::LANG, "") + .replace(RESET, ""); assert!(plain.starts_with("TypeScript Mutations (1 total)")); } @@ -109,5 +127,3 @@ mod tests { assert!(out.starts_with('[')); } } - - diff --git a/crates/bough-cli/src/show_single_mutation.rs b/crates/bough-cli/src/show_single_mutation.rs index 5f14cd15..769c7d22 100644 --- a/crates/bough-cli/src/show_single_mutation.rs +++ b/crates/bough-cli/src/show_single_mutation.rs @@ -4,7 +4,7 @@ use bough_core::{LanguageId, Session, State}; use bough_typed_hash::{TypedHashable, UnvalidatedHash}; use crate::config::Config; -use crate::render::{BOLD, TITLE, RESET, Render}; +use crate::render::{BOLD, RESET, Render, TITLE}; // TODO: decompose into smaller types (e.g. CodeDiff) and delegate Render to them pub struct ShowSingleMutation { @@ -17,7 +17,9 @@ pub struct ShowSingleMutation { impl ShowSingleMutation { pub fn run(mut session: impl DerefMut>, hash: &str) -> Box { session.tend_add_missing_states().expect("tend states"); - let mutation = session.resolve_mutation(UnvalidatedHash::new(hash.to_string())).expect("resolve mutation"); + let mutation = session + .resolve_mutation(UnvalidatedHash::new(hash.to_string())) + .expect("resolve mutation"); let base = session.base(); let lang = mutation.mutant().lang(); let file_path = bough_core::File::new(base, mutation.mutant().twig()).resolve(); @@ -119,8 +121,7 @@ mod tests { #[test] fn markdown() { - let plain = fixture().markdown() - .replace(TITLE, "").replace(RESET, ""); + let plain = fixture().markdown().replace(TITLE, "").replace(RESET, ""); assert!(plain.starts_with("# Mutation")); assert!(plain.contains("```typescript\nconst x = 1;\n```")); assert!(plain.contains("```typescript\nconst x = 2;\n```")); @@ -134,8 +135,7 @@ mod tests { #[test] fn verbose() { - let plain = fixture().verbose() - .replace(BOLD, "").replace(RESET, ""); + let plain = fixture().verbose().replace(BOLD, "").replace(RESET, ""); assert!(plain.contains("Before:\nconst x = 1;")); assert!(plain.contains("After:\nconst x = 2;")); } @@ -147,5 +147,3 @@ mod tests { assert!(out.contains("mutation")); } } - - diff --git a/crates/bough-cli/src/step_apply_mutation.rs b/crates/bough-cli/src/step_apply_mutation.rs index dc663528..0ca87fc3 100644 --- a/crates/bough-cli/src/step_apply_mutation.rs +++ b/crates/bough-cli/src/step_apply_mutation.rs @@ -1,6 +1,6 @@ use bough_typed_hash::TypedHashable; -use crate::render::{MUTATION, TITLE, WORKSPACE, RESET, Render}; +use crate::render::{MUTATION, RESET, Render, TITLE, WORKSPACE}; pub struct StepApplyMutation { pub workspace_id: bough_core::WorkspaceId, @@ -8,7 +8,10 @@ pub struct StepApplyMutation { } impl StepApplyMutation { - pub fn run(workspace: &mut bough_core::Workspace, mutation: &bough_core::Mutation) -> Result, bough_core::WorkspaceError> { + pub fn run( + workspace: &mut bough_core::Workspace, + mutation: &bough_core::Mutation, + ) -> Result, bough_core::WorkspaceError> { workspace.write_mutant(mutation)?; Ok(Box::new(Self { workspace_id: workspace.id().clone(), @@ -73,8 +76,12 @@ mod tests { #[test] fn verbose() { - let plain = fixture().verbose() - .replace(TITLE, "").replace(MUTATION, "").replace(WORKSPACE, "").replace(RESET, ""); + let plain = fixture() + .verbose() + .replace(TITLE, "") + .replace(MUTATION, "") + .replace(WORKSPACE, "") + .replace(RESET, ""); assert_eq!(plain, "Apply Mutation abcdef12 to aaaa1111"); } @@ -85,5 +92,3 @@ mod tests { assert!(out.contains(r#""mutation_hash":"abcdef12""#)); } } - - diff --git a/crates/bough-cli/src/step_init_workspace.rs b/crates/bough-cli/src/step_init_workspace.rs index 01ddbf9b..3288c5b4 100644 --- a/crates/bough-cli/src/step_init_workspace.rs +++ b/crates/bough-cli/src/step_init_workspace.rs @@ -1,5 +1,5 @@ use crate::config::Config; -use crate::render::{TITLE, WORKSPACE, RESET, Render}; +use crate::render::{RESET, Render, TITLE, WORKSPACE}; pub struct StepInitWorkspace { pub workspace_id: bough_core::WorkspaceId, @@ -7,7 +7,11 @@ pub struct StepInitWorkspace { } impl StepInitWorkspace { - pub fn run(workspace: &bough_core::Workspace, config: &Config, timeout: Option) -> Result, bough_core::PhaseError> { + pub fn run( + workspace: &bough_core::Workspace, + config: &Config, + timeout: Option, + ) -> Result, bough_core::PhaseError> { let outcome = workspace.run_init(config, timeout)?; Ok(Box::new(Self { workspace_id: workspace.id().clone(), @@ -58,7 +62,12 @@ mod tests { fn fixture() -> StepInitWorkspace { StepInitWorkspace { workspace_id: WorkspaceId::parse("aaaa1111").unwrap(), - outcome: PhaseOutcome::Completed { exit_code: 0, duration: std::time::Duration::from_secs(1), stdout: vec![], stderr: vec![] }, + outcome: PhaseOutcome::Completed { + exit_code: 0, + duration: std::time::Duration::from_secs(1), + stdout: vec![], + stderr: vec![], + }, } } @@ -77,7 +86,11 @@ mod tests { #[test] fn verbose() { - let plain = fixture().verbose().replace(TITLE, "").replace(WORKSPACE, "").replace(RESET, ""); + let plain = fixture() + .verbose() + .replace(TITLE, "") + .replace(WORKSPACE, "") + .replace(RESET, ""); assert!(plain.starts_with("Init Workspace aaaa1111")); } @@ -88,5 +101,3 @@ mod tests { assert!(out.contains(r#""outcome":"#)); } } - - diff --git a/crates/bough-cli/src/step_reset_workspace.rs b/crates/bough-cli/src/step_reset_workspace.rs index 2d11576f..8b221926 100644 --- a/crates/bough-cli/src/step_reset_workspace.rs +++ b/crates/bough-cli/src/step_reset_workspace.rs @@ -1,5 +1,5 @@ use crate::config::Config; -use crate::render::{TITLE, WORKSPACE, RESET, Render}; +use crate::render::{RESET, Render, TITLE, WORKSPACE}; pub struct StepResetWorkspace { pub workspace_id: bough_core::WorkspaceId, @@ -7,7 +7,11 @@ pub struct StepResetWorkspace { } impl StepResetWorkspace { - pub fn run(workspace: &bough_core::Workspace, config: &Config, timeout: Option) -> Result, bough_core::PhaseError> { + pub fn run( + workspace: &bough_core::Workspace, + config: &Config, + timeout: Option, + ) -> Result, bough_core::PhaseError> { let outcome = workspace.run_reset(config, timeout)?; Ok(Box::new(Self { workspace_id: workspace.id().clone(), @@ -58,7 +62,12 @@ mod tests { fn fixture() -> StepResetWorkspace { StepResetWorkspace { workspace_id: WorkspaceId::parse("aaaa1111").unwrap(), - outcome: PhaseOutcome::Completed { exit_code: 0, duration: std::time::Duration::from_secs(1), stdout: vec![], stderr: vec![] }, + outcome: PhaseOutcome::Completed { + exit_code: 0, + duration: std::time::Duration::from_secs(1), + stdout: vec![], + stderr: vec![], + }, } } @@ -77,7 +86,11 @@ mod tests { #[test] fn verbose() { - let plain = fixture().verbose().replace(TITLE, "").replace(WORKSPACE, "").replace(RESET, ""); + let plain = fixture() + .verbose() + .replace(TITLE, "") + .replace(WORKSPACE, "") + .replace(RESET, ""); assert!(plain.starts_with("Reset Workspace aaaa1111")); } @@ -87,5 +100,3 @@ mod tests { assert!(out.contains(r#""workspace_id":"aaaa1111""#)); } } - - diff --git a/crates/bough-cli/src/step_tend_state.rs b/crates/bough-cli/src/step_tend_state.rs index a349ef1f..3f1b4adc 100644 --- a/crates/bough-cli/src/step_tend_state.rs +++ b/crates/bough-cli/src/step_tend_state.rs @@ -3,7 +3,7 @@ use std::ops::DerefMut; use bough_core::Session; use crate::config::Config; -use crate::render::{MUTATION, TITLE, RESET, Render}; +use crate::render::{MUTATION, RESET, Render, TITLE}; pub struct StepTendState { pub added: Vec, @@ -75,7 +75,11 @@ mod tests { Span::new(Point::new(0, 0, 0), Point::new(2, 3, 20)), Span::new(Point::new(0, 0, 0), Point::new(2, 3, 20)), ); - let hash = MutationIter::new(&mutant).next().unwrap().hash().expect("hash"); + let hash = MutationIter::new(&mutant) + .next() + .unwrap() + .hash() + .expect("hash"); StepTendState { added: vec![hash], removed: vec![], @@ -96,7 +100,10 @@ mod tests { #[test] fn verbose() { let out = fixture().verbose(); - let plain = out.replace(TITLE, "").replace(MUTATION, "").replace(RESET, ""); + let plain = out + .replace(TITLE, "") + .replace(MUTATION, "") + .replace(RESET, ""); assert!(plain.starts_with("Tend State +1 -0\n")); } @@ -107,5 +114,3 @@ mod tests { assert!(out.contains(r#""removed":[]"#)); } } - - diff --git a/crates/bough-cli/src/step_tend_workspaces.rs b/crates/bough-cli/src/step_tend_workspaces.rs index 48c95578..e1a4854a 100644 --- a/crates/bough-cli/src/step_tend_workspaces.rs +++ b/crates/bough-cli/src/step_tend_workspaces.rs @@ -3,7 +3,7 @@ use std::ops::DerefMut; use bough_core::Session; use crate::config::Config; -use crate::render::{TITLE, WORKSPACE, RESET, Render}; +use crate::render::{RESET, Render, TITLE, WORKSPACE}; pub struct StepTendWorkspaces { pub workspace_ids: Vec, @@ -53,7 +53,11 @@ impl Render for StepTendWorkspaces { } fn json(&self) -> String { - let items: Vec = self.workspace_ids.iter().map(|id| format!("\"{id}\"")).collect(); + let items: Vec = self + .workspace_ids + .iter() + .map(|id| format!("\"{id}\"")) + .collect(); format!("[{}]", items.join(",")) } } @@ -86,7 +90,11 @@ mod tests { #[test] fn verbose() { - let plain = fixture().verbose().replace(TITLE, "").replace(WORKSPACE, "").replace(RESET, ""); + let plain = fixture() + .verbose() + .replace(TITLE, "") + .replace(WORKSPACE, "") + .replace(RESET, ""); assert!(plain.starts_with("Tend Workspaces (2 total)")); } @@ -97,5 +105,3 @@ mod tests { assert!(out.contains("aaaa1111")); } } - - diff --git a/crates/bough-cli/src/step_test_mutation.rs b/crates/bough-cli/src/step_test_mutation.rs index 5a21e3a0..b5b4ed5b 100644 --- a/crates/bough-cli/src/step_test_mutation.rs +++ b/crates/bough-cli/src/step_test_mutation.rs @@ -1,7 +1,7 @@ use bough_typed_hash::TypedHashable; use crate::config::Config; -use crate::render::{MUTATION, TITLE, WORKSPACE, RESET, Render}; +use crate::render::{MUTATION, RESET, Render, TITLE, WORKSPACE}; pub struct StepTestMutation { pub workspace_id: bough_core::WorkspaceId, @@ -12,19 +12,20 @@ pub struct StepTestMutation { } impl StepTestMutation { - pub fn run(workspace: &bough_core::Workspace, config: &Config, mutation: &bough_core::Mutation, timeout: Option) -> Result, bough_core::PhaseError> { + pub fn run( + workspace: &bough_core::Workspace, + config: &Config, + mutation: &bough_core::Mutation, + timeout: Option, + ) -> Result, bough_core::PhaseError> { let outcome = workspace.run_test(config, timeout)?; let duration = outcome.duration(); let (status_value, status_str) = match outcome { - bough_core::PhaseOutcome::TimedOut { .. } => { - (bough_core::Status::Timeout, "timeout") - } + bough_core::PhaseOutcome::TimedOut { .. } => (bough_core::Status::Timeout, "timeout"), bough_core::PhaseOutcome::Completed { exit_code, .. } if exit_code != 0 => { (bough_core::Status::Caught, "caught") } - bough_core::PhaseOutcome::Completed { .. } => { - (bough_core::Status::Missed, "missed") - } + bough_core::PhaseOutcome::Completed { .. } => (bough_core::Status::Missed, "missed"), }; Ok(Box::new(Self { workspace_id: workspace.id().clone(), @@ -109,8 +110,12 @@ mod tests { #[test] fn verbose() { - let plain = fixture().verbose() - .replace(TITLE, "").replace(MUTATION, "").replace(WORKSPACE, "").replace(RESET, ""); + let plain = fixture() + .verbose() + .replace(TITLE, "") + .replace(MUTATION, "") + .replace(WORKSPACE, "") + .replace(RESET, ""); assert!(plain.starts_with("Test Mutation abcdef12 in aaaa1111")); } @@ -121,5 +126,3 @@ mod tests { assert!(out.contains(r#""duration_secs":0.500"#)); } } - - diff --git a/crates/bough-cli/src/step_unapply_mutation.rs b/crates/bough-cli/src/step_unapply_mutation.rs index 418973cd..59784f2a 100644 --- a/crates/bough-cli/src/step_unapply_mutation.rs +++ b/crates/bough-cli/src/step_unapply_mutation.rs @@ -1,6 +1,6 @@ use bough_typed_hash::TypedHashable; -use crate::render::{MUTATION, TITLE, WORKSPACE, RESET, Render}; +use crate::render::{MUTATION, RESET, Render, TITLE, WORKSPACE}; pub struct StepUnapplyMutation { pub workspace_id: bough_core::WorkspaceId, @@ -8,8 +8,11 @@ pub struct StepUnapplyMutation { } impl StepUnapplyMutation { - pub fn run(workspace: &mut bough_core::Workspace) -> Result, bough_core::WorkspaceError> { - let mutation_hash = workspace.active() + pub fn run( + workspace: &mut bough_core::Workspace, + ) -> Result, bough_core::WorkspaceError> { + let mutation_hash = workspace + .active() .map(|a| format!("{}", a.mutation().hash().expect("hash"))) .unwrap_or_default(); workspace.revert_mutant()?; @@ -76,8 +79,12 @@ mod tests { #[test] fn verbose() { - let plain = fixture().verbose() - .replace(TITLE, "").replace(MUTATION, "").replace(WORKSPACE, "").replace(RESET, ""); + let plain = fixture() + .verbose() + .replace(TITLE, "") + .replace(MUTATION, "") + .replace(WORKSPACE, "") + .replace(RESET, ""); assert_eq!(plain, "Unapply Mutation abcdef12 from aaaa1111"); } @@ -88,5 +95,3 @@ mod tests { assert!(out.contains(r#""mutation_hash":"abcdef12""#)); } } - - diff --git a/crates/bough-core/src/base.rs b/crates/bough-core/src/base.rs index d7b690b3..9d61536e 100644 --- a/crates/bough-core/src/base.rs +++ b/crates/bough-core/src/base.rs @@ -28,7 +28,12 @@ impl Base { }) } - pub fn add_mutator(&mut self, language_id: LanguageId, files: TwigsIterBuilder, skip_queries: Vec) { + pub fn add_mutator( + &mut self, + language_id: LanguageId, + files: TwigsIterBuilder, + skip_queries: Vec, + ) { debug!(lang = ?language_id, skip_queries = ?skip_queries, "added mutator"); self.mutant_files.insert(language_id, (files, skip_queries)); } diff --git a/crates/bough-core/src/bin/bough-test-helper.rs b/crates/bough-core/src/bin/bough-test-helper.rs index 80486941..d11c9cfc 100644 --- a/crates/bough-core/src/bin/bough-test-helper.rs +++ b/crates/bough-core/src/bin/bough-test-helper.rs @@ -57,7 +57,9 @@ fn spawn_own_pgroup(args: &[String]) { use std::os::unix::process::CommandExt; use std::sync::atomic::Ordering; - let pid_dir = args.first().expect("spawn-own-pgroup requires a pid-dir path"); + let pid_dir = args + .first() + .expect("spawn-own-pgroup requires a pid-dir path"); let pid_dir = std::path::Path::new(pid_dir); std::fs::write(pid_dir.join("parent.pid"), std::process::id().to_string()).unwrap(); @@ -76,7 +78,10 @@ fn spawn_own_pgroup(args: &[String]) { CHILD_PID_FOR_HANDLER.store(child_pid, Ordering::SeqCst); unsafe { - libc::signal(libc::SIGTERM, handle_sigterm as *const () as libc::sighandler_t); + libc::signal( + libc::SIGTERM, + handle_sigterm as *const () as libc::sighandler_t, + ); } let _ = child.wait(); @@ -88,9 +93,13 @@ static CHILD_PID_FOR_HANDLER: std::sync::atomic::AtomicI32 = std::sync::atomic:: extern "C" fn handle_sigterm(_sig: libc::c_int) { let child_pid = CHILD_PID_FOR_HANDLER.load(std::sync::atomic::Ordering::SeqCst); if child_pid > 0 { - unsafe { libc::kill(-child_pid, libc::SIGKILL); } + unsafe { + libc::kill(-child_pid, libc::SIGKILL); + } + } + unsafe { + libc::_exit(0); } - unsafe { libc::_exit(0); } } fn spawn_and_wait(args: &[String]) { diff --git a/crates/bough-core/src/language/c.rs b/crates/bough-core/src/language/c.rs index 04f509bf..1c195cc8 100644 --- a/crates/bough-core/src/language/c.rs +++ b/crates/bough-core/src/language/c.rs @@ -102,11 +102,7 @@ impl LanguageDriver for CDriver { } "number_literal" => { let span = span_from_node(node); - Some(( - MutantKind::Literal(LiteralKind::Number), - span.clone(), - span, - )) + Some((MutantKind::Literal(LiteralKind::Number), span.clone(), span)) } "string_literal" => { let text = node.utf8_text(file_content).ok()?; @@ -183,11 +179,7 @@ impl LanguageDriver for CDriver { MutantKind::StatementBlock => vec!["{}".into()], MutantKind::Condition => vec!["1".into(), "0".into()], MutantKind::SwitchCase => vec!["".into()], - MutantKind::Literal(LiteralKind::Number) => vec![ - "0".into(), - "1".into(), - "-1".into(), - ], + MutantKind::Literal(LiteralKind::Number) => vec!["0".into(), "1".into(), "-1".into()], MutantKind::Literal(LiteralKind::String) => vec!["\"\"".into()], MutantKind::Literal(LiteralKind::EmptyString) => vec!["\"bough\"".into()], MutantKind::ArrayDecl(ArrayDeclKind::Inline) => vec!["{}".into()], @@ -197,10 +189,7 @@ impl LanguageDriver for CDriver { } fn is_context_boundary(&self, node: &arborium_tree_sitter::Node<'_>) -> bool { - matches!( - node.kind(), - "function_definition" | "struct_specifier" - ) + matches!(node.kind(), "function_definition" | "struct_specifier") } } @@ -215,11 +204,22 @@ mod tests { let text = node.utf8_text(src).unwrap_or(""); let field = node.parent().and_then(|p| { (0..p.child_count()) - .find(|&i| p.child(i as u32).map(|c| c.id() == node.id()).unwrap_or(false)) + .find(|&i| { + p.child(i as u32) + .map(|c| c.id() == node.id()) + .unwrap_or(false) + }) .and_then(|i| p.field_name_for_child(i as u32)) }); let field_str = field.map(|f| format!("{f}: ")).unwrap_or_default(); - eprintln!("{:indent$}{field_str}{} [{}-{}] {text:?}", "", node.kind(), node.start_byte(), node.end_byte(), indent=indent); + eprintln!( + "{:indent$}{field_str}{} [{}-{}] {text:?}", + "", + node.kind(), + node.start_byte(), + node.end_byte(), + indent = indent + ); for i in 0..node.child_count() { if let Some(child) = node.child(i as u32) { print_node(&child, src, indent + 2); diff --git a/crates/bough-core/src/language/cs.rs b/crates/bough-core/src/language/cs.rs index 3b677781..f534bc66 100644 --- a/crates/bough-core/src/language/cs.rs +++ b/crates/bough-core/src/language/cs.rs @@ -96,11 +96,7 @@ impl LanguageDriver for CSharpDriver { } "integer_literal" | "real_literal" => { let span = span_from_node(node); - Some(( - MutantKind::Literal(LiteralKind::Number), - span.clone(), - span, - )) + Some((MutantKind::Literal(LiteralKind::Number), span.clone(), span)) } "string_literal" => { let text = node.utf8_text(file_content).ok()?; @@ -230,7 +226,11 @@ mod tests { let text = node.utf8_text(src).unwrap_or(""); let field = node.parent().and_then(|p| { (0..p.child_count()) - .find(|&i| p.child(i as u32).map(|c| c.id() == node.id()).unwrap_or(false)) + .find(|&i| { + p.child(i as u32) + .map(|c| c.id() == node.id()) + .unwrap_or(false) + }) .and_then(|i| p.field_name_for_child(i as u32)) }); let field_str = field.map(|f| format!("{f}: ")).unwrap_or_default(); diff --git a/crates/bough-core/src/language/go.rs b/crates/bough-core/src/language/go.rs index 97b35b7d..b6f929df 100644 --- a/crates/bough-core/src/language/go.rs +++ b/crates/bough-core/src/language/go.rs @@ -98,11 +98,7 @@ impl LanguageDriver for GoDriver { } "int_literal" | "float_literal" => { let span = span_from_node(node); - Some(( - MutantKind::Literal(LiteralKind::Number), - span.clone(), - span, - )) + Some((MutantKind::Literal(LiteralKind::Number), span.clone(), span)) } "interpreted_string_literal" | "raw_string_literal" => { let text = node.utf8_text(file_content).ok()?; @@ -222,10 +218,7 @@ impl LanguageDriver for GoDriver { } fn is_context_boundary(&self, node: &arborium_tree_sitter::Node<'_>) -> bool { - matches!( - node.kind(), - "function_declaration" | "method_declaration" - ) + matches!(node.kind(), "function_declaration" | "method_declaration") } } @@ -240,11 +233,22 @@ mod tests { let text = node.utf8_text(src).unwrap_or(""); let field = node.parent().and_then(|p| { (0..p.child_count()) - .find(|&i| p.child(i as u32).map(|c| c.id() == node.id()).unwrap_or(false)) + .find(|&i| { + p.child(i as u32) + .map(|c| c.id() == node.id()) + .unwrap_or(false) + }) .and_then(|i| p.field_name_for_child(i as u32)) }); let field_str = field.map(|f| format!("{f}: ")).unwrap_or_default(); - eprintln!("{:indent$}{field_str}{} [{}-{}] {text:?}", "", node.kind(), node.start_byte(), node.end_byte(), indent=indent); + eprintln!( + "{:indent$}{field_str}{} [{}-{}] {text:?}", + "", + node.kind(), + node.start_byte(), + node.end_byte(), + indent = indent + ); for i in 0..node.child_count() { if let Some(child) = node.child(i as u32) { print_node(&child, src, indent + 2); @@ -257,7 +261,8 @@ mod tests { #[test] #[ignore] fn debug_tree() { - dump_tree(r#"package main + dump_tree( + r#"package main func example() { x := a + b @@ -280,6 +285,7 @@ func example() { return } } -"#); +"#, + ); } } diff --git a/crates/bough-core/src/language/java.rs b/crates/bough-core/src/language/java.rs index 19fe7813..f8c5a935 100644 --- a/crates/bough-core/src/language/java.rs +++ b/crates/bough-core/src/language/java.rs @@ -97,11 +97,7 @@ impl LanguageDriver for JavaDriver { } "decimal_integer_literal" | "decimal_floating_point_literal" => { let span = span_from_node(node); - Some(( - MutantKind::Literal(LiteralKind::Number), - span.clone(), - span, - )) + Some((MutantKind::Literal(LiteralKind::Number), span.clone(), span)) } "string_literal" => { let text = node.utf8_text(file_content).ok()?; @@ -232,11 +228,22 @@ mod tests { let text = node.utf8_text(src).unwrap_or(""); let field = node.parent().and_then(|p| { (0..p.child_count()) - .find(|&i| p.child(i as u32).map(|c| c.id() == node.id()).unwrap_or(false)) + .find(|&i| { + p.child(i as u32) + .map(|c| c.id() == node.id()) + .unwrap_or(false) + }) .and_then(|i| p.field_name_for_child(i as u32)) }); let field_str = field.map(|f| format!("{f}: ")).unwrap_or_default(); - eprintln!("{:indent$}{field_str}{} [{}-{}] {text:?}", "", node.kind(), node.start_byte(), node.end_byte(), indent=indent); + eprintln!( + "{:indent$}{field_str}{} [{}-{}] {text:?}", + "", + node.kind(), + node.start_byte(), + node.end_byte(), + indent = indent + ); for i in 0..node.child_count() { if let Some(child) = node.child(i as u32) { print_node(&child, src, indent + 2); diff --git a/crates/bough-core/src/language/javascript.rs b/crates/bough-core/src/language/javascript.rs index 7bc32373..50f12c83 100644 --- a/crates/bough-core/src/language/javascript.rs +++ b/crates/bough-core/src/language/javascript.rs @@ -33,7 +33,11 @@ impl LanguageDriver for JavascriptDriver { } else { condition }; - Some((MutantKind::Condition, span_from_node(&inner), span_from_node(node))) + Some(( + MutantKind::Condition, + span_from_node(&inner), + span_from_node(node), + )) } // bough[impl mutant.twig-iter.find.js.binary.add] // bough[impl mutant.twig-iter.find.js.binary.sub] @@ -64,7 +68,11 @@ impl LanguageDriver for JavascriptDriver { "<=" => BinaryOpMutationKind::Lte, _ => return None, }; - Some((MutantKind::BinaryOp(kind), span_from_node(&op_node), span_from_node(node))) + Some(( + MutantKind::BinaryOp(kind), + span_from_node(&op_node), + span_from_node(node), + )) } "augmented_assignment_expression" => { let op_node = node.child_by_field_name("operator")?; @@ -84,7 +92,11 @@ impl LanguageDriver for JavascriptDriver { "||=" => AssignMutationKind::OrAssign, _ => return None, }; - Some((MutantKind::Assign(kind), span_from_node(&op_node), span_from_node(node))) + Some(( + MutantKind::Assign(kind), + span_from_node(&op_node), + span_from_node(node), + )) } "assignment_expression" => { let op_node = (0..node.child_count()) @@ -98,7 +110,11 @@ impl LanguageDriver for JavascriptDriver { } "array" if node.named_child_count() > 0 => { let span = span_from_node(node); - Some((MutantKind::ArrayDecl(ArrayDeclKind::Inline), span.clone(), span)) + Some(( + MutantKind::ArrayDecl(ArrayDeclKind::Inline), + span.clone(), + span, + )) } "new_expression" => { let callee = node.child_by_field_name("constructor")?; @@ -106,7 +122,11 @@ impl LanguageDriver for JavascriptDriver { let args = node.child_by_field_name("arguments")?; if args.named_child_count() > 0 { let span = span_from_node(node); - Some((MutantKind::ArrayDecl(ArrayDeclKind::Instance), span.clone(), span)) + Some(( + MutantKind::ArrayDecl(ArrayDeclKind::Instance), + span.clone(), + span, + )) } else { None } @@ -120,11 +140,19 @@ impl LanguageDriver for JavascriptDriver { } "true" => { let span = span_from_node(node); - Some((MutantKind::Literal(LiteralKind::BoolTrue), span.clone(), span)) + Some(( + MutantKind::Literal(LiteralKind::BoolTrue), + span.clone(), + span, + )) } "false" => { let span = span_from_node(node); - Some((MutantKind::Literal(LiteralKind::BoolFalse), span.clone(), span)) + Some(( + MutantKind::Literal(LiteralKind::BoolFalse), + span.clone(), + span, + )) } "string" => { let text = node.utf8_text(file_content).ok()?; @@ -142,7 +170,9 @@ impl LanguageDriver for JavascriptDriver { } "switch_case" | "switch_default" => { let parent = node.parent()?; - if parent.kind() != "switch_body" { return None; } + if parent.kind() != "switch_body" { + return None; + } let switch_stmt = parent.parent()?; let span = span_from_node(node); Some((MutantKind::SwitchCase, span, span_from_node(&switch_stmt))) @@ -157,7 +187,11 @@ impl LanguageDriver for JavascriptDriver { "call_expression" => OptionalChainKind::FnCall, _ => unreachable!(), }; - Some((MutantKind::OptionalChain(kind), span_from_node(&oc), span_from_node(node))) + Some(( + MutantKind::OptionalChain(kind), + span_from_node(&oc), + span_from_node(node), + )) } _ => None, }; @@ -252,4 +286,3 @@ impl LanguageDriver for JavascriptDriver { } } } - diff --git a/crates/bough-core/src/language/mod.rs b/crates/bough-core/src/language/mod.rs index 0cd7dadb..d6ae0c2e 100644 --- a/crates/bough-core/src/language/mod.rs +++ b/crates/bough-core/src/language/mod.rs @@ -1,19 +1,19 @@ mod c; mod cs; mod go; -mod rs; mod java; mod javascript; mod python; +mod rs; mod typescript; pub(crate) use c::CDriver; pub(crate) use cs::CSharpDriver; pub(crate) use go::GoDriver; -pub(crate) use rs::RustDriver; pub(crate) use java::JavaDriver; pub(crate) use javascript::JavascriptDriver; pub(crate) use python::PythonDriver; +pub(crate) use rs::RustDriver; pub(crate) use typescript::TypescriptDriver; use crate::mutant::{MutantKind, Span}; diff --git a/crates/bough-core/src/language/python.rs b/crates/bough-core/src/language/python.rs index 3c7abd79..0068991d 100644 --- a/crates/bough-core/src/language/python.rs +++ b/crates/bough-core/src/language/python.rs @@ -33,7 +33,11 @@ impl LanguageDriver for PythonDriver { "//" => BinaryOpMutationKind::FloorDiv, _ => return None, }; - Some((MutantKind::BinaryOp(kind), span_from_node(&op_node), span_from_node(node))) + Some(( + MutantKind::BinaryOp(kind), + span_from_node(&op_node), + span_from_node(node), + )) } "comparison_operator" => { let op_node = node.child_by_field_name("operators")?; @@ -51,7 +55,11 @@ impl LanguageDriver for PythonDriver { "not in" => BinaryOpMutationKind::NotIn, _ => return None, }; - Some((MutantKind::BinaryOp(kind), span_from_node(&op_node), span_from_node(node))) + Some(( + MutantKind::BinaryOp(kind), + span_from_node(&op_node), + span_from_node(node), + )) } "augmented_assignment" => { let op_node = node.child_by_field_name("operator")?; @@ -71,7 +79,11 @@ impl LanguageDriver for PythonDriver { "//=" => AssignMutationKind::FloorDivAssign, _ => return None, }; - Some((MutantKind::Assign(kind), span_from_node(&op_node), span_from_node(node))) + Some(( + MutantKind::Assign(kind), + span_from_node(&op_node), + span_from_node(node), + )) } "assignment" => { let op_node = (0..node.child_count()) @@ -89,19 +101,29 @@ impl LanguageDriver for PythonDriver { } "if_statement" | "while_statement" => { let condition = node.child_by_field_name("condition")?; - Some((MutantKind::Condition, span_from_node(&condition), span_from_node(node))) + Some(( + MutantKind::Condition, + span_from_node(&condition), + span_from_node(node), + )) } "generator_expression" | "tuple" if node.named_child_count() > 0 => { let span = span_from_node(node); Some((MutantKind::TupleDecl, span.clone(), span)) } - "set_comprehension" | "dictionary_comprehension" | "dictionary" if node.named_child_count() > 0 => { + "set_comprehension" | "dictionary_comprehension" | "dictionary" + if node.named_child_count() > 0 => + { let span = span_from_node(node); Some((MutantKind::DictDecl, span.clone(), span)) } "list_comprehension" | "list" if node.named_child_count() > 0 => { let span = span_from_node(node); - Some((MutantKind::ArrayDecl(crate::mutant::ArrayDeclKind::Inline), span.clone(), span)) + Some(( + MutantKind::ArrayDecl(crate::mutant::ArrayDeclKind::Inline), + span.clone(), + span, + )) } "boolean_operator" => { let op_node = node.child_by_field_name("operator")?; @@ -111,7 +133,11 @@ impl LanguageDriver for PythonDriver { "or" => BinaryOpMutationKind::Or, _ => return None, }; - Some((MutantKind::BinaryOp(kind), span_from_node(&op_node), span_from_node(node))) + Some(( + MutantKind::BinaryOp(kind), + span_from_node(&op_node), + span_from_node(node), + )) } "string" => { let text = node.utf8_text(file_content).ok()?; @@ -125,7 +151,11 @@ impl LanguageDriver for PythonDriver { } "integer" | "float" => { let span = span_from_node(node); - Some((MutantKind::Literal(crate::mutant::LiteralKind::Number), span.clone(), span)) + Some(( + MutantKind::Literal(crate::mutant::LiteralKind::Number), + span.clone(), + span, + )) } "assert_statement" => { let span = span_from_node(node); @@ -135,15 +165,27 @@ impl LanguageDriver for PythonDriver { let not_node = (0..node.child_count()) .filter_map(|i| node.child(i as u32)) .find(|c| c.kind() == "not")?; - Some((MutantKind::UnaryNot, span_from_node(¬_node), span_from_node(node))) + Some(( + MutantKind::UnaryNot, + span_from_node(¬_node), + span_from_node(node), + )) } "true" => { let span = span_from_node(node); - Some((MutantKind::Literal(crate::mutant::LiteralKind::BoolTrue), span.clone(), span)) + Some(( + MutantKind::Literal(crate::mutant::LiteralKind::BoolTrue), + span.clone(), + span, + )) } "false" => { let span = span_from_node(node); - Some((MutantKind::Literal(crate::mutant::LiteralKind::BoolFalse), span.clone(), span)) + Some(( + MutantKind::Literal(crate::mutant::LiteralKind::BoolFalse), + span.clone(), + span, + )) } _ => None, }; @@ -201,7 +243,9 @@ impl LanguageDriver for PythonDriver { MutantKind::Assert => vec!["pass".into()], MutantKind::UnaryNot => vec!["".into()], MutantKind::Literal(crate::mutant::LiteralKind::String) => vec!["\"\"".into()], - MutantKind::Literal(crate::mutant::LiteralKind::EmptyString) => vec!["\"bough\"".into()], + MutantKind::Literal(crate::mutant::LiteralKind::EmptyString) => { + vec!["\"bough\"".into()] + } MutantKind::Literal(crate::mutant::LiteralKind::Number) => vec![ "0".into(), "1".into(), @@ -234,11 +278,22 @@ mod tests { let text = node.utf8_text(src).unwrap_or(""); let field = node.parent().and_then(|p| { (0..p.child_count()) - .find(|&i| p.child(i as u32).map(|c| c.id() == node.id()).unwrap_or(false)) + .find(|&i| { + p.child(i as u32) + .map(|c| c.id() == node.id()) + .unwrap_or(false) + }) .and_then(|i| p.field_name_for_child(i as u32)) }); let field_str = field.map(|f| format!("{f}: ")).unwrap_or_default(); - eprintln!("{:indent$}{field_str}{} [{}-{}] {text:?}", "", node.kind(), node.start_byte(), node.end_byte(), indent=indent); + eprintln!( + "{:indent$}{field_str}{} [{}-{}] {text:?}", + "", + node.kind(), + node.start_byte(), + node.end_byte(), + indent = indent + ); for i in 0..node.child_count() { if let Some(child) = node.child(i as u32) { print_node(&child, src, indent + 2); diff --git a/crates/bough-core/src/language/rs.rs b/crates/bough-core/src/language/rs.rs index 060ecae3..13ac450f 100644 --- a/crates/bough-core/src/language/rs.rs +++ b/crates/bough-core/src/language/rs.rs @@ -53,10 +53,7 @@ impl LanguageDriver for RustDriver { // See https://github.com/CodeEnPlace/bough/issues/38 let left = node.child_by_field_name("left")?; if left.kind() == "range_expression" { - let has_left_operand = left - .child(0) - .map(|c| c.kind() != "..") - .unwrap_or(false); + let has_left_operand = left.child(0).map(|c| c.kind() != "..").unwrap_or(false); if !has_left_operand { let eq_node = (0..node.child_count()) .filter_map(|i| node.child(i as u32)) @@ -170,19 +167,11 @@ impl LanguageDriver for RustDriver { } let pattern_span = span_from_node(node); let arm = node.parent()?; - Some(( - MutantKind::MatchPattern, - pattern_span, - span_from_node(&arm), - )) + Some((MutantKind::MatchPattern, pattern_span, span_from_node(&arm))) } "integer_literal" | "float_literal" => { let span = span_from_node(node); - Some(( - MutantKind::Literal(LiteralKind::Number), - span.clone(), - span, - )) + Some((MutantKind::Literal(LiteralKind::Number), span.clone(), span)) } "string_literal" => { let text = node.utf8_text(file_content).ok()?; @@ -304,12 +293,7 @@ impl LanguageDriver for RustDriver { fn is_context_boundary(&self, node: &arborium_tree_sitter::Node<'_>) -> bool { matches!( node.kind(), - "function_item" - | "impl_item" - | "struct_item" - | "enum_item" - | "trait_item" - | "mod_item" + "function_item" | "impl_item" | "struct_item" | "enum_item" | "trait_item" | "mod_item" ) } } @@ -325,7 +309,11 @@ mod tests { let text = node.utf8_text(src).unwrap_or(""); let field = node.parent().and_then(|p| { (0..p.child_count()) - .find(|&i| p.child(i as u32).map(|c| c.id() == node.id()).unwrap_or(false)) + .find(|&i| { + p.child(i as u32) + .map(|c| c.id() == node.id()) + .unwrap_or(false) + }) .and_then(|i| p.field_name_for_child(i as u32)) }); let field_str = field.map(|f| format!("{f}: ")).unwrap_or_default(); diff --git a/crates/bough-core/src/language/typescript.rs b/crates/bough-core/src/language/typescript.rs index 1a7d30d4..d3f36719 100644 --- a/crates/bough-core/src/language/typescript.rs +++ b/crates/bough-core/src/language/typescript.rs @@ -29,7 +29,11 @@ impl LanguageDriver for TypescriptDriver { } else { condition }; - Some((MutantKind::Condition, span_from_node(&inner), span_from_node(node))) + Some(( + MutantKind::Condition, + span_from_node(&inner), + span_from_node(node), + )) } "binary_expression" => { let op_node = node.child_by_field_name("operator")?; @@ -58,7 +62,11 @@ impl LanguageDriver for TypescriptDriver { "<=" => BinaryOpMutationKind::Lte, _ => return None, }; - Some((MutantKind::BinaryOp(kind), span_from_node(&op_node), span_from_node(node))) + Some(( + MutantKind::BinaryOp(kind), + span_from_node(&op_node), + span_from_node(node), + )) } "augmented_assignment_expression" => { let op_node = node.child_by_field_name("operator")?; @@ -78,7 +86,11 @@ impl LanguageDriver for TypescriptDriver { "||=" => AssignMutationKind::OrAssign, _ => return None, }; - Some((MutantKind::Assign(kind), span_from_node(&op_node), span_from_node(node))) + Some(( + MutantKind::Assign(kind), + span_from_node(&op_node), + span_from_node(node), + )) } "assignment_expression" => { let op_node = (0..node.child_count()) @@ -92,7 +104,11 @@ impl LanguageDriver for TypescriptDriver { } "array" if node.named_child_count() > 0 => { let span = span_from_node(node); - Some((MutantKind::ArrayDecl(ArrayDeclKind::Inline), span.clone(), span)) + Some(( + MutantKind::ArrayDecl(ArrayDeclKind::Inline), + span.clone(), + span, + )) } "new_expression" => { let callee = node.child_by_field_name("constructor")?; @@ -100,7 +116,11 @@ impl LanguageDriver for TypescriptDriver { let args = node.child_by_field_name("arguments")?; if args.named_child_count() > 0 { let span = span_from_node(node); - Some((MutantKind::ArrayDecl(ArrayDeclKind::Instance), span.clone(), span)) + Some(( + MutantKind::ArrayDecl(ArrayDeclKind::Instance), + span.clone(), + span, + )) } else { None } @@ -114,11 +134,19 @@ impl LanguageDriver for TypescriptDriver { } "true" => { let span = span_from_node(node); - Some((MutantKind::Literal(LiteralKind::BoolTrue), span.clone(), span)) + Some(( + MutantKind::Literal(LiteralKind::BoolTrue), + span.clone(), + span, + )) } "false" => { let span = span_from_node(node); - Some((MutantKind::Literal(LiteralKind::BoolFalse), span.clone(), span)) + Some(( + MutantKind::Literal(LiteralKind::BoolFalse), + span.clone(), + span, + )) } "string" => { let text = node.utf8_text(file_content).ok()?; @@ -136,7 +164,9 @@ impl LanguageDriver for TypescriptDriver { } "switch_case" | "switch_default" => { let parent = node.parent()?; - if parent.kind() != "switch_body" { return None; } + if parent.kind() != "switch_body" { + return None; + } let switch_stmt = parent.parent()?; let span = span_from_node(node); Some((MutantKind::SwitchCase, span, span_from_node(&switch_stmt))) @@ -151,7 +181,11 @@ impl LanguageDriver for TypescriptDriver { "call_expression" => OptionalChainKind::FnCall, _ => unreachable!(), }; - Some((MutantKind::OptionalChain(kind), span_from_node(&oc), span_from_node(node))) + Some(( + MutantKind::OptionalChain(kind), + span_from_node(&oc), + span_from_node(node), + )) } _ => None, }; @@ -244,4 +278,3 @@ impl LanguageDriver for TypescriptDriver { } } } - diff --git a/crates/bough-core/src/mutant.rs b/crates/bough-core/src/mutant.rs index c9ffe583..bb3740cb 100644 --- a/crates/bough-core/src/mutant.rs +++ b/crates/bough-core/src/mutant.rs @@ -1,13 +1,19 @@ use crate::language::{LanguageDriver, driver_for_lang}; use crate::{LanguageId, base::Base, file::Twig}; +use arborium_tree_sitter::StreamingIterator; use bough_typed_hash::{HashInto, TypedHashable}; use tracing::{debug, trace}; -use arborium_tree_sitter::StreamingIterator; #[derive(Debug, Clone, PartialEq, Eq)] pub enum EncompassError { - LangMismatch { outer: LanguageId, inner: LanguageId }, - TwigMismatch { outer: Twig, inner: Twig }, + LangMismatch { + outer: LanguageId, + inner: LanguageId, + }, + TwigMismatch { + outer: Twig, + inner: Twig, + }, } // bough[impl mutant.twig-iter.twig] @@ -44,7 +50,13 @@ pub struct Mutant { } impl Mutant { - pub fn new(lang: LanguageId, twig: Twig, kind: MutantKind, span: Span, effect_span: Span) -> Self { + pub fn new( + lang: LanguageId, + twig: Twig, + kind: MutantKind, + span: Span, + effect_span: Span, + ) -> Self { Self { lang, twig, @@ -76,7 +88,10 @@ impl Mutant { pub fn encompasses(&self, inner: &Mutant) -> Result { if self.lang != inner.lang { - return Err(EncompassError::LangMismatch { outer: self.lang, inner: inner.lang }); + return Err(EncompassError::LangMismatch { + outer: self.lang, + inner: inner.lang, + }); } if self.twig != inner.twig { return Err(EncompassError::TwigMismatch { @@ -412,9 +427,9 @@ pub enum MutantKind { impl MutantKind { pub fn all_variants() -> Vec { - use BinaryOpMutationKind::*; - use AssignMutationKind::*; use ArrayDeclKind::*; + use AssignMutationKind::*; + use BinaryOpMutationKind::*; use LiteralKind::*; use OptionalChainKind::*; @@ -554,13 +569,33 @@ impl MutantKind { "BinaryOp" => { use BinaryOpMutationKind::*; let k = match inner { - "Add" => Add, "And" => And, "BitAnd" => BitAnd, "BitOr" => BitOr, - "BitXor" => BitXor, "Div" => Div, "Eq" => Eq, "Exp" => Exp, - "FloorDiv" => FloorDiv, "Gt" => Gt, "In" => In, "Is" => Is, - "IsNot" => IsNot, "NotIn" => NotIn, "Gte" => Gte, "Lt" => Lt, - "Lte" => Lte, "Mul" => Mul, "Or" => Or, "Rem" => Rem, - "Shl" => Shl, "Shr" => Shr, "StrictEq" => StrictEq, "Ne" => Ne, - "StrictNe" => StrictNe, "Sub" => Sub, "Xor" => Xor, + "Add" => Add, + "And" => And, + "BitAnd" => BitAnd, + "BitOr" => BitOr, + "BitXor" => BitXor, + "Div" => Div, + "Eq" => Eq, + "Exp" => Exp, + "FloorDiv" => FloorDiv, + "Gt" => Gt, + "In" => In, + "Is" => Is, + "IsNot" => IsNot, + "NotIn" => NotIn, + "Gte" => Gte, + "Lt" => Lt, + "Lte" => Lte, + "Mul" => Mul, + "Or" => Or, + "Rem" => Rem, + "Shl" => Shl, + "Shr" => Shr, + "StrictEq" => StrictEq, + "Ne" => Ne, + "StrictNe" => StrictNe, + "Sub" => Sub, + "Xor" => Xor, _ => return None, }; Some(MutantKind::BinaryOp(k)) @@ -568,13 +603,20 @@ impl MutantKind { "Assign" => { use AssignMutationKind::*; let k = match inner { - "AddAssign" => AddAssign, "AndAssign" => AndAssign, - "BitAndAssign" => BitAndAssign, "BitOrAssign" => BitOrAssign, - "BitXorAssign" => BitXorAssign, "DivAssign" => DivAssign, - "ExpAssign" => ExpAssign, "FloorDivAssign" => FloorDivAssign, - "MulAssign" => MulAssign, "NormalAssign" => NormalAssign, - "OrAssign" => OrAssign, "RemAssign" => RemAssign, - "ShlAssign" => ShlAssign, "ShrAssign" => ShrAssign, + "AddAssign" => AddAssign, + "AndAssign" => AndAssign, + "BitAndAssign" => BitAndAssign, + "BitOrAssign" => BitOrAssign, + "BitXorAssign" => BitXorAssign, + "DivAssign" => DivAssign, + "ExpAssign" => ExpAssign, + "FloorDivAssign" => FloorDivAssign, + "MulAssign" => MulAssign, + "NormalAssign" => NormalAssign, + "OrAssign" => OrAssign, + "RemAssign" => RemAssign, + "ShlAssign" => ShlAssign, + "ShrAssign" => ShrAssign, "SubAssign" => SubAssign, _ => return None, }; @@ -591,8 +633,11 @@ impl MutantKind { "Literal" => { use LiteralKind::*; let k = match inner { - "BoolTrue" => BoolTrue, "BoolFalse" => BoolFalse, - "String" => String, "EmptyString" => EmptyString, "Number" => Number, + "BoolTrue" => BoolTrue, + "BoolFalse" => BoolFalse, + "String" => String, + "EmptyString" => EmptyString, + "Number" => Number, _ => return None, }; Some(MutantKind::Literal(k)) @@ -640,9 +685,10 @@ impl<'a, 't> TwigMutantsIter<'a, 't> { // SAFETY: we store the Tree alongside the TreeCursor and never move or drop // the Tree while the cursor is alive. The cursor is invalidated before the tree. let cursor = unsafe { - std::mem::transmute::, arborium_tree_sitter::TreeCursor<'static>>( - tree.walk(), - ) + std::mem::transmute::< + arborium_tree_sitter::TreeCursor<'_>, + arborium_tree_sitter::TreeCursor<'static>, + >(tree.walk()) }; Ok(Self { @@ -717,7 +763,9 @@ impl<'a, 't> Iterator for TwigMutantsIter<'a, 't> { let Some(node) = node else { continue }; - if let Some((kind, span, effect_span)) = self.driver.check_node(&node, &self.file_content) { + if let Some((kind, span, effect_span)) = + self.driver.check_node(&node, &self.file_content) + { if self.skip_kinds.contains(&kind) { trace!(?kind, "skipping mutant by kind filter"); continue; diff --git a/crates/bough-core/src/mutation.rs b/crates/bough-core/src/mutation.rs index 6de92452..41eba74b 100644 --- a/crates/bough-core/src/mutation.rs +++ b/crates/bough-core/src/mutation.rs @@ -174,8 +174,6 @@ mod tests { } } - - // bough[verify mutation.subst.js.cond.false] #[test] fn js_condition_mutant_has_false_substitution() { diff --git a/crates/bough-core/src/mutation_score.rs b/crates/bough-core/src/mutation_score.rs index 7f6db9e6..9f534c22 100644 --- a/crates/bough-core/src/mutation_score.rs +++ b/crates/bough-core/src/mutation_score.rs @@ -2,8 +2,8 @@ use std::sync::Arc; use facet::Facet; -use crate::{Mutation, base::Base}; use crate::language::driver_for_lang; +use crate::{Mutation, base::Base}; #[derive(Facet, Debug, Clone, Copy, PartialEq, Eq)] #[repr(u8)] @@ -54,7 +54,9 @@ impl MutationScorer { let value = match &self.factor { Factor::TSNodeDepth => self.score_ts_node_depth(&mutation), - Factor::EncompasingMissedMutationsCount => self.score_encompassing_missed(&mutation, states), + Factor::EncompasingMissedMutationsCount => { + self.score_encompassing_missed(&mutation, states) + } Factor::FileAuthorCount => todo!(), Factor::MutationSeverity => todo!(), Factor::SiblingMissedMutations => todo!(), @@ -93,7 +95,11 @@ impl MutationScorer { depth } - fn score_encompassing_missed(&self, mutation: &Mutation, states: &[crate::state::State]) -> u64 { + fn score_encompassing_missed( + &self, + mutation: &Mutation, + states: &[crate::state::State], + ) -> u64 { let target = mutation.mutant(); states .iter() @@ -135,11 +141,16 @@ mod tests { use super::*; fn make_scorer(min: u64, max: u64) -> MutationScorer { - let base = Arc::new(crate::base::Base::new( - std::env::temp_dir(), - crate::twig::TwigsIterBuilder::new(), - ).unwrap()); - MutationScorer { base, factor: Factor::TSNodeDepth, min, max } + let base = Arc::new( + crate::base::Base::new(std::env::temp_dir(), crate::twig::TwigsIterBuilder::new()) + .unwrap(), + ); + MutationScorer { + base, + factor: Factor::TSNodeDepth, + min, + max, + } } #[test] @@ -221,11 +232,11 @@ mod tests { mod ts_node_depth { use super::*; + use crate::LanguageId; use crate::file::Twig; - use crate::mutant::{MutantKind, BinaryOpMutationKind, TwigMutantsIter}; + use crate::mutant::{BinaryOpMutationKind, MutantKind, TwigMutantsIter}; use crate::mutation::MutationIter; use crate::twig::TwigsIterBuilder; - use crate::LanguageId; use std::path::PathBuf; fn make_js_base(content: &str) -> (tempfile::TempDir, crate::base::Base) { @@ -235,7 +246,8 @@ mod tests { let base = crate::base::Base::new( dir.path().to_path_buf(), TwigsIterBuilder::new().with_include_glob("src/**/*.js"), - ).unwrap(); + ) + .unwrap(); (dir, base) } @@ -260,12 +272,16 @@ mod tests { fn top_level_statement_block_is_shallow() { let (_dir, base) = make_js_base("function foo() { return 1; }"); let scores = score_all(&base); - let block_scores: Vec<_> = scores.iter() + let block_scores: Vec<_> = scores + .iter() .filter(|(k, _)| matches!(k, MutantKind::StatementBlock)) .collect(); assert_eq!(block_scores.len(), 1); let depth = block_scores[0].1; - assert!(depth <= 3, "top-level block depth {depth} should be shallow"); + assert!( + depth <= 3, + "top-level block depth {depth} should be shallow" + ); } #[test] @@ -273,15 +289,22 @@ mod tests { let js = "function foo() { if (x) { return a + b; } }"; let (_dir, base) = make_js_base(js); let scores = score_all(&base); - let block_depth = scores.iter() + let block_depth = scores + .iter() .filter(|(k, _)| matches!(k, MutantKind::StatementBlock)) .map(|(_, d)| *d) - .min().unwrap(); - let add_depth = scores.iter() + .min() + .unwrap(); + let add_depth = scores + .iter() .filter(|(k, _)| matches!(k, MutantKind::BinaryOp(BinaryOpMutationKind::Add))) .map(|(_, d)| *d) - .next().unwrap(); - assert!(add_depth > block_depth, "add depth {add_depth} should be deeper than block depth {block_depth}"); + .next() + .unwrap(); + assert!( + add_depth > block_depth, + "add depth {add_depth} should be deeper than block depth {block_depth}" + ); } #[test] @@ -294,7 +317,8 @@ mod tests { .unwrap() .flat_map(|bm| MutationIter::new(&bm.into_mutant()).collect::>()) .collect(); - let scores: Vec<_> = mutations.into_iter() + let scores: Vec<_> = mutations + .into_iter() .map(|m| scorer.score(m, &[])) .collect(); let viewer = scorer.into_viewer(); @@ -306,12 +330,12 @@ mod tests { } mod encompasing_missed_mutations_count { use super::*; + use crate::LanguageId; use crate::file::Twig; - use crate::mutant::{MutantKind, BinaryOpMutationKind, TwigMutantsIter}; + use crate::mutant::{BinaryOpMutationKind, MutantKind, TwigMutantsIter}; use crate::mutation::{Mutation, MutationIter}; use crate::state::{State, Status}; use crate::twig::TwigsIterBuilder; - use crate::LanguageId; use std::path::PathBuf; fn make_js_base(content: &str) -> (tempfile::TempDir, crate::base::Base) { @@ -321,7 +345,8 @@ mod tests { let base = crate::base::Base::new( dir.path().to_path_buf(), TwigsIterBuilder::new().with_include_glob("src/**/*.js"), - ).unwrap(); + ) + .unwrap(); (dir, base) } @@ -334,7 +359,8 @@ mod tests { } fn first_mutation_of_kind(mutations: &[Mutation], kind: &MutantKind) -> Mutation { - mutations.iter() + mutations + .iter() .find(|m| m.mutant().kind() == kind) .unwrap_or_else(|| panic!("no mutation of kind {kind:?}")) .clone() @@ -371,7 +397,10 @@ mod tests { let (_dir, base) = make_js_base("if (x) { y() + z() }"); let mutations = all_mutations(&base); let condition = first_mutation_of_kind(&mutations, &MutantKind::Condition); - let binop = first_mutation_of_kind(&mutations, &MutantKind::BinaryOp(BinaryOpMutationKind::Add)); + let binop = first_mutation_of_kind( + &mutations, + &MutantKind::BinaryOp(BinaryOpMutationKind::Add), + ); let states = vec![ make_missed_state(condition.clone()), @@ -382,8 +411,12 @@ mod tests { let binop_score = scorer.score(binop, &states); let condition_score = scorer.score(condition, &states); - assert!(binop_score.0 > condition_score.0, - "binop score {} should be higher than condition score {}", binop_score.0, condition_score.0); + assert!( + binop_score.0 > condition_score.0, + "binop score {} should be higher than condition score {}", + binop_score.0, + condition_score.0 + ); } #[test] @@ -391,7 +424,10 @@ mod tests { let (_dir, base) = make_js_base("if (x) { y() + z() }"); let mutations = all_mutations(&base); let condition = first_mutation_of_kind(&mutations, &MutantKind::Condition); - let binop = first_mutation_of_kind(&mutations, &MutantKind::BinaryOp(BinaryOpMutationKind::Add)); + let binop = first_mutation_of_kind( + &mutations, + &MutantKind::BinaryOp(BinaryOpMutationKind::Add), + ); let states = vec![make_missed_state(binop)]; @@ -405,7 +441,10 @@ mod tests { let (_dir, base) = make_js_base("if (x) { y() + z() }"); let mutations = all_mutations(&base); let condition = first_mutation_of_kind(&mutations, &MutantKind::Condition); - let binop = first_mutation_of_kind(&mutations, &MutantKind::BinaryOp(BinaryOpMutationKind::Add)); + let binop = first_mutation_of_kind( + &mutations, + &MutantKind::BinaryOp(BinaryOpMutationKind::Add), + ); let states = vec![make_missed_state(condition)]; @@ -419,7 +458,10 @@ mod tests { let (_dir, base) = make_js_base("if (x) { y() + z() }"); let mutations = all_mutations(&base); let condition = first_mutation_of_kind(&mutations, &MutantKind::Condition); - let binop = first_mutation_of_kind(&mutations, &MutantKind::BinaryOp(BinaryOpMutationKind::Add)); + let binop = first_mutation_of_kind( + &mutations, + &MutantKind::BinaryOp(BinaryOpMutationKind::Add), + ); let states = vec![make_caught_state(condition)]; @@ -448,12 +490,12 @@ mod tests { let mutations = all_mutations(&base); let condition = first_mutation_of_kind(&mutations, &MutantKind::Condition); let block = first_mutation_of_kind(&mutations, &MutantKind::StatementBlock); - let binop = first_mutation_of_kind(&mutations, &MutantKind::BinaryOp(BinaryOpMutationKind::Add)); + let binop = first_mutation_of_kind( + &mutations, + &MutantKind::BinaryOp(BinaryOpMutationKind::Add), + ); - let states = vec![ - make_missed_state(condition), - make_missed_state(block), - ]; + let states = vec![make_missed_state(condition), make_missed_state(block)]; let mut scorer = make_scorer(&base); let score = scorer.score(binop, &states); @@ -463,12 +505,17 @@ mod tests { // Two disjoint functions: mutations in one should not encompass mutations in the other #[test] fn disjoint_missed_mutations_score_zero() { - let (_dir, base) = make_js_base( - "function foo() { return a + b; }\nfunction bar() { return c - d; }" - ); + let (_dir, base) = + make_js_base("function foo() { return a + b; }\nfunction bar() { return c - d; }"); let mutations = all_mutations(&base); - let add = first_mutation_of_kind(&mutations, &MutantKind::BinaryOp(BinaryOpMutationKind::Add)); - let sub = first_mutation_of_kind(&mutations, &MutantKind::BinaryOp(BinaryOpMutationKind::Sub)); + let add = first_mutation_of_kind( + &mutations, + &MutantKind::BinaryOp(BinaryOpMutationKind::Add), + ); + let sub = first_mutation_of_kind( + &mutations, + &MutantKind::BinaryOp(BinaryOpMutationKind::Sub), + ); let states = vec![make_missed_state(sub)]; @@ -482,7 +529,10 @@ mod tests { let (_dir, base) = make_js_base("if (x) { y() + z() }"); let mutations = all_mutations(&base); let condition = first_mutation_of_kind(&mutations, &MutantKind::Condition); - let binop = first_mutation_of_kind(&mutations, &MutantKind::BinaryOp(BinaryOpMutationKind::Add)); + let binop = first_mutation_of_kind( + &mutations, + &MutantKind::BinaryOp(BinaryOpMutationKind::Add), + ); let states = vec![ make_missed_state(condition.clone()), diff --git a/crates/bough-core/src/phase.rs b/crates/bough-core/src/phase.rs index 79ccd0c9..46195a16 100644 --- a/crates/bough-core/src/phase.rs +++ b/crates/bough-core/src/phase.rs @@ -50,14 +50,18 @@ fn kill_process_tree(child: &mut std::process::Child) { use wait_timeout::ChildExt; let pid = child.id() as i32; - unsafe { libc::kill(-pid, libc::SIGTERM); } + unsafe { + libc::kill(-pid, libc::SIGTERM); + } match child.wait_timeout(GRACEFUL_SHUTDOWN_PERIOD) { Ok(Some(_)) => return, _ => {} } - unsafe { libc::kill(-pid, libc::SIGKILL); } + unsafe { + libc::kill(-pid, libc::SIGKILL); + } } #[cfg(not(unix))] { @@ -414,7 +418,10 @@ mod tests { }; assert_eq!(outcome.stdout(), b"hello\n"); assert_eq!(outcome.stderr(), b"warn\n"); - assert!(matches!(outcome, PhaseOutcome::Completed { exit_code: 0, .. })); + assert!(matches!( + outcome, + PhaseOutcome::Completed { exit_code: 0, .. } + )); assert_eq!(outcome.duration(), std::time::Duration::from_millis(150)); } @@ -427,7 +434,10 @@ mod tests { exit_code: 1, duration: std::time::Duration::from_millis(50), }; - assert!(matches!(outcome, PhaseOutcome::Completed { exit_code: 1, .. })); + assert!(matches!( + outcome, + PhaseOutcome::Completed { exit_code: 1, .. } + )); } // bough[verify phase.out] @@ -455,7 +465,10 @@ mod tests { ..make_phase(&root) }; let outcome = phase.run().unwrap(); - assert!(matches!(outcome, PhaseOutcome::Completed { exit_code: 0, .. })); + assert!(matches!( + outcome, + PhaseOutcome::Completed { exit_code: 0, .. } + )); assert_eq!(String::from_utf8_lossy(outcome.stdout()).trim(), "hello"); } @@ -471,7 +484,10 @@ mod tests { ..make_phase(&root) }; let outcome = phase.run().unwrap(); - assert!(matches!(outcome, PhaseOutcome::Completed { exit_code: 42, .. })); + assert!(matches!( + outcome, + PhaseOutcome::Completed { exit_code: 42, .. } + )); } // bough[verify phase.run.pwd] @@ -568,7 +584,10 @@ mod tests { ..make_phase(&root) }; let outcome = phase.run().unwrap(); - assert!(matches!(outcome, PhaseOutcome::Completed { exit_code: 0, .. })); + assert!(matches!( + outcome, + PhaseOutcome::Completed { exit_code: 0, .. } + )); } fn helper_bin() -> PathBuf { @@ -592,7 +611,10 @@ mod tests { ..make_phase(&root) }; let outcome = phase.run().unwrap(); - assert!(matches!(outcome, PhaseOutcome::Completed { exit_code: 0, .. })); + assert!(matches!( + outcome, + PhaseOutcome::Completed { exit_code: 0, .. } + )); assert!( outcome.stdout().len() > 64 * 1024, "expected >64KB stdout, got {}", diff --git a/crates/bough-core/src/session.rs b/crates/bough-core/src/session.rs index a7c31e20..6b0abbfd 100644 --- a/crates/bough-core/src/session.rs +++ b/crates/bough-core/src/session.rs @@ -118,11 +118,19 @@ impl Session { &self.base } - pub fn resolve_mutation(&self, unvalidated: bough_typed_hash::UnvalidatedHash) -> Result { + pub fn resolve_mutation( + &self, + unvalidated: bough_typed_hash::UnvalidatedHash, + ) -> Result { let mutations: Vec = self.base.mutations().collect::>()?; let hashes: Vec = mutations.iter().map(|m| m.hash().expect("hash")).collect(); - let matched = unvalidated.validate(&hashes).expect("hash resolution failed"); - Ok(mutations.into_iter().find(|m| m.hash().unwrap() == matched).unwrap()) + let matched = unvalidated + .validate(&hashes) + .expect("hash resolution failed"); + Ok(mutations + .into_iter() + .find(|m| m.hash().unwrap() == matched) + .unwrap()) } fn derive_mutations_needing_testing( @@ -892,7 +900,10 @@ mod tests { config.test_cmd = "echo hello".to_string(); let session = Session::new(config.clone()).unwrap(); let outcome = session.base().run_test(&config, None).unwrap(); - assert!(matches!(outcome, crate::phase::PhaseOutcome::Completed { exit_code: 0, .. })); + assert!(matches!( + outcome, + crate::phase::PhaseOutcome::Completed { exit_code: 0, .. } + )); assert_eq!(String::from_utf8_lossy(outcome.stdout()).trim(), "hello"); } @@ -930,7 +941,10 @@ mod tests { config.test_cmd = "false".to_string(); let session = Session::new(config.clone()).unwrap(); let outcome = session.base().run_test(&config, None).unwrap(); - assert!(matches!(outcome, crate::phase::PhaseOutcome::Completed { exit_code: 1, .. })); + assert!(matches!( + outcome, + crate::phase::PhaseOutcome::Completed { exit_code: 1, .. } + )); } #[test] @@ -940,7 +954,10 @@ mod tests { config.init_cmd = Some("echo init".to_string()); let session = Session::new(config.clone()).unwrap(); let outcome = session.base().run_init(&config, None).unwrap(); - assert!(matches!(outcome, crate::phase::PhaseOutcome::Completed { exit_code: 0, .. })); + assert!(matches!( + outcome, + crate::phase::PhaseOutcome::Completed { exit_code: 0, .. } + )); assert_eq!(String::from_utf8_lossy(outcome.stdout()).trim(), "init"); } @@ -960,7 +977,10 @@ mod tests { config.reset_cmd = Some("echo reset".to_string()); let session = Session::new(config.clone()).unwrap(); let outcome = session.base().run_reset(&config, None).unwrap(); - assert!(matches!(outcome, crate::phase::PhaseOutcome::Completed { exit_code: 0, .. })); + assert!(matches!( + outcome, + crate::phase::PhaseOutcome::Completed { exit_code: 0, .. } + )); assert_eq!(String::from_utf8_lossy(outcome.stdout()).trim(), "reset"); } @@ -1022,7 +1042,10 @@ mod tests { let ids = session.tend_workspaces(1).unwrap(); let workspace = session.bind_workspace(&ids[0]).unwrap(); let outcome = workspace.run_init(&config, None).unwrap(); - assert!(matches!(outcome, crate::phase::PhaseOutcome::Completed { exit_code: 0, .. })); + assert!(matches!( + outcome, + crate::phase::PhaseOutcome::Completed { exit_code: 0, .. } + )); assert_eq!( String::from_utf8_lossy(outcome.stdout()).trim(), "workspace_init" @@ -1051,7 +1074,10 @@ mod tests { let ids = session.tend_workspaces(1).unwrap(); let workspace = session.bind_workspace(&ids[0]).unwrap(); let outcome = workspace.run_reset(&config, None).unwrap(); - assert!(matches!(outcome, crate::phase::PhaseOutcome::Completed { exit_code: 0, .. })); + assert!(matches!( + outcome, + crate::phase::PhaseOutcome::Completed { exit_code: 0, .. } + )); assert_eq!( String::from_utf8_lossy(outcome.stdout()).trim(), "workspace_reset" @@ -1284,13 +1310,20 @@ mod tests { fn find_best_mutations_respects_number_limit() { let dir = tempfile::tempdir().unwrap(); let mut config = make_js_config(dir.path()); - std::fs::write(dir.path().join("src/a.js"), "function foo() { return a + b; }").unwrap(); + std::fs::write( + dir.path().join("src/a.js"), + "function foo() { return a + b; }", + ) + .unwrap(); config.find_number = 2; config.find_number_per_file = 10; let mut session = Session::new(config).unwrap(); session.tend_add_missing_states().unwrap(); let total = session.get_count_mutation_needing_test(); - assert!(total > 2, "need more than 2 mutations to test limit, got {total}"); + assert!( + total > 2, + "need more than 2 mutations to test limit, got {total}" + ); let results = session.find_best_mutations().unwrap(); assert_eq!(results.len(), 2); @@ -1300,20 +1333,30 @@ mod tests { fn find_best_mutations_respects_number_per_file_limit() { let dir = tempfile::tempdir().unwrap(); let mut config = make_js_config(dir.path()); - std::fs::write(dir.path().join("src/a.js"), "function foo() { return a + b; }").unwrap(); - std::fs::write(dir.path().join("src/b.js"), "function bar() { return c - d; }").unwrap(); + std::fs::write( + dir.path().join("src/a.js"), + "function foo() { return a + b; }", + ) + .unwrap(); + std::fs::write( + dir.path().join("src/b.js"), + "function bar() { return c - d; }", + ) + .unwrap(); config.find_number = 100; config.find_number_per_file = 1; let mut session = Session::new(config).unwrap(); session.tend_add_missing_states().unwrap(); let results = session.find_best_mutations().unwrap(); - let a_count = results.iter().filter(|(_, s, _)| { - s.mutation().mutant().twig().path().ends_with("a.js") - }).count(); - let b_count = results.iter().filter(|(_, s, _)| { - s.mutation().mutant().twig().path().ends_with("b.js") - }).count(); + let a_count = results + .iter() + .filter(|(_, s, _)| s.mutation().mutant().twig().path().ends_with("a.js")) + .count(); + let b_count = results + .iter() + .filter(|(_, s, _)| s.mutation().mutant().twig().path().ends_with("b.js")) + .count(); assert_eq!(a_count, 1); assert_eq!(b_count, 1); } @@ -1330,8 +1373,11 @@ mod tests { let total_before = session.get_count_mutation_needing_test(); let mutation: Mutation = session.base().mutations().next().unwrap().unwrap(); - session.set_state(&mutation, crate::state::Status::Caught).unwrap(); - session.mutations_needing_test = Session::::derive_mutations_needing_testing(&session.mutations_state); + session + .set_state(&mutation, crate::state::Status::Caught) + .unwrap(); + session.mutations_needing_test = + Session::::derive_mutations_needing_testing(&session.mutations_state); let results = session.find_best_mutations().unwrap(); assert_eq!(results.len(), total_before - 1); @@ -1350,7 +1396,12 @@ mod tests { let results = session.find_best_mutations().unwrap(); assert!(results.len() > 1); for w in results.windows(2) { - assert!(w[0].2 >= w[1].2, "results should be sorted descending by score: {} >= {}", w[0].2, w[1].2); + assert!( + w[0].2 >= w[1].2, + "results should be sorted descending by score: {} >= {}", + w[0].2, + w[1].2 + ); } } diff --git a/crates/bough-corpus-tests/src/lib.rs b/crates/bough-corpus-tests/src/lib.rs index 33dc3a1c..db3cc441 100644 --- a/crates/bough-corpus-tests/src/lib.rs +++ b/crates/bough-corpus-tests/src/lib.rs @@ -69,7 +69,8 @@ fn corpus_test_runner(case_dir: &str, lang: LanguageId, ext: &str) { } else { let existing = std::fs::read_to_string(&src_path).unwrap(); assert_eq!( - existing, *mutated_src, + existing, + *mutated_src, "mutation content mismatch in {}", src_path.display() ); @@ -84,13 +85,12 @@ fn corpus_test_runner(case_dir: &str, lang: LanguageId, ext: &str) { } else { let existing = std::fs::read_to_string(&json_path).unwrap(); assert_eq!( - existing, json, + existing, + json, "mutation json mismatch in {}", json_path.display() ); } - - } produced_files.insert(format!("base.{ext}")); diff --git a/crates/bough-docs-cli/src/bin/seed_examples.rs b/crates/bough-docs-cli/src/bin/seed_examples.rs index 5902d0d7..3ce61221 100644 --- a/crates/bough-docs-cli/src/bin/seed_examples.rs +++ b/crates/bough-docs-cli/src/bin/seed_examples.rs @@ -49,7 +49,10 @@ fn seed_language(lang: &bough_core::LanguageId) { } let source_len = source.len(); - if best.get(&key).is_none_or(|(_, prev_len)| source_len < *prev_len) { + if best + .get(&key) + .is_none_or(|(_, prev_len)| source_len < *prev_len) + { best.insert(key, (source.clone(), source_len)); } } @@ -88,9 +91,5 @@ fn seed_language(lang: &bough_core::LanguageId) { fs::write(&out_path, &out).unwrap_or_else(|e| { panic!("failed to write {}: {e}", out_path.display()); }); - eprintln!( - " wrote {} ({} examples)", - out_path.display(), - best.len() - ); + eprintln!(" wrote {} ({} examples)", out_path.display(), best.len()); } diff --git a/crates/bough-docs-cli/src/build.rs b/crates/bough-docs-cli/src/build.rs index 857b37b1..d7cb27a7 100644 --- a/crates/bough-docs-cli/src/build.rs +++ b/crates/bough-docs-cli/src/build.rs @@ -368,10 +368,7 @@ fn make_mutation_reference(lang: &bough_core::LanguageId) -> String { // Parse the snippet in-memory to find mutants of this kind let source_mutants = bough_core::find_mutants_in_source(*lang, snippet.as_bytes()); - let matching: Vec<_> = source_mutants - .iter() - .filter(|m| m.kind == kind) - .collect(); + let matching: Vec<_> = source_mutants.iter().filter(|m| m.kind == kind).collect(); if matching.is_empty() { panic!( @@ -382,23 +379,14 @@ fn make_mutation_reference(lang: &bough_core::LanguageId) -> String { } let _ = writeln!(out, "## {}\n", kind.heading()); - let _ = writeln!( - out, - "### Before\n\n```{ext}\n{}\n```\n", - snippet.trim_end() - ); + let _ = writeln!(out, "### Before\n\n```{ext}\n{}\n```\n", snippet.trim_end()); let _ = writeln!(out, "### After\n"); for mutant in &matching { let span_start = mutant.subst_span.start().byte(); let span_end = mutant.subst_span.end().byte(); for sub in &subs { - let mutated = format!( - "{}{}{}", - &snippet[..span_start], - sub, - &snippet[span_end..], - ); + let mutated = format!("{}{}{}", &snippet[..span_start], sub, &snippet[span_end..],); let _ = writeln!(out, "```{ext}\n{}\n```\n", mutated.trim_end()); } } @@ -533,8 +521,7 @@ mod tests { #[test] fn all_example_files_are_valid() { // Tests run from crate dir; examples are relative to workspace root - let workspace_root = - Path::new(env!("CARGO_MANIFEST_DIR")).join("..").join(".."); + let workspace_root = Path::new(env!("CARGO_MANIFEST_DIR")).join("..").join(".."); std::env::set_current_dir(&workspace_root).expect("failed to cd to workspace root"); for lang in bough_core::LanguageId::ALL { diff --git a/crates/bough-docs-cli/src/facet_reference.rs b/crates/bough-docs-cli/src/facet_reference.rs index 9360f79d..ecfe9a46 100644 --- a/crates/bough-docs-cli/src/facet_reference.rs +++ b/crates/bough-docs-cli/src/facet_reference.rs @@ -11,7 +11,12 @@ pub fn make_facet_reference<'a, T: Facet<'a>>() -> String { out } -fn render_shape(shape: &'static Shape, out: &mut String, heading_level: usize, visited: &mut HashSet<&'static str>) { +fn render_shape( + shape: &'static Shape, + out: &mut String, + heading_level: usize, + visited: &mut HashSet<&'static str>, +) { if !visited.insert(shape.type_identifier) { return; } @@ -84,8 +89,16 @@ fn render_field_row(field: &'static Field, out: &mut String, nested: &mut Vec<&' let field_shape = field.shape(); let type_name = display_type_name(field_shape); let doc = join_doc(field.doc); - let default_note = if field.has_default() { " *(optional)*" } else { "" }; - let _ = writeln!(out, "| `{}` | `{type_name}` | {doc}{default_note} |", field.effective_name()); + let default_note = if field.has_default() { + " *(optional)*" + } else { + "" + }; + let _ = writeln!( + out, + "| `{}` | `{type_name}` | {doc}{default_note} |", + field.effective_name() + ); collect_nested(field_shape, nested); } @@ -108,7 +121,11 @@ fn display_type_name(shape: &'static Shape) -> String { match shape.def { Def::Option(opt) => format!("{}?", display_type_name(opt.t)), Def::List(list) => format!("{}[]", display_type_name(list.t)), - Def::Map(map) => format!("Map<{}, {}>", display_type_name(map.k), display_type_name(map.v)), + Def::Map(map) => format!( + "Map<{}, {}>", + display_type_name(map.k), + display_type_name(map.v) + ), _ => shape.type_identifier.to_string(), } } diff --git a/crates/bough-docs-cli/src/serve.rs b/crates/bough-docs-cli/src/serve.rs index 1c6da569..505f1a1e 100644 --- a/crates/bough-docs-cli/src/serve.rs +++ b/crates/bough-docs-cli/src/serve.rs @@ -59,8 +59,7 @@ pub fn serve(port: u16) { .wait_while(lock.lock().unwrap(), |g| *g == current) .unwrap(); - let header = - Header::from_bytes("Content-Type", "application/javascript").unwrap(); + let header = Header::from_bytes("Content-Type", "application/javascript").unwrap(); let _ = request .respond(Response::from_string("window.location.reload()").with_header(header)); }); @@ -102,7 +101,9 @@ pub fn serve(port: u16) { let content = if content_type == "text/html; charset=utf-8" { let mut html = String::from_utf8_lossy(&content).into_owned(); - html.push_str("\n"); + html.push_str( + "\n", + ); html.into_bytes() } else { content