From 869123fc4577bd9e649cc8bdc73d0122b31ec6b5 Mon Sep 17 00:00:00 2001 From: Freddie Ridell Date: Sat, 7 Mar 2026 22:13:39 +0000 Subject: [PATCH] Show mutations filtered by language and file (show mutations ) --- crates/bough-cli/src/main.rs | 19 +++++++++++++++---- crates/bough-cli/src/render.rs | 25 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/crates/bough-cli/src/main.rs b/crates/bough-cli/src/main.rs index 0a1a2a41..d9df527a 100644 --- a/crates/bough-cli/src/main.rs +++ b/crates/bough-cli/src/main.rs @@ -6,7 +6,7 @@ use config::{Command, Show, parse}; use render::{Noop, Render}; use tracing::{Level, debug, info}; -use crate::render::{AllMutations, BaseFiles, LangMutations, MutantFiles}; +use crate::render::{AllMutations, BaseFiles, FileMutations, LangMutations, MutantFiles}; fn main() { let cli = parse(); @@ -86,9 +86,20 @@ fn main() { } Show::Mutations { - lang: Some(_lang), - file: Some(_file), - } => todo!(), + lang: Some(lang), + file: Some(file), + } => { + let session = Session::new(cli.config.clone()).expect("session creation"); + let base = session.base(); + let mutations: Vec<_> = base + .mutations() + .collect::, _>>() + .expect("mutation scan") + .into_iter() + .filter(|m| m.mutant().lang() == *lang && m.mutant().twig().path() == file.as_path()) + .collect(); + Box::new(FileMutations(*lang, file.clone(), mutations)) + } Show::Mutation { hash } => todo!(), } diff --git a/crates/bough-cli/src/render.rs b/crates/bough-cli/src/render.rs index 04908dc8..5948d0e9 100644 --- a/crates/bough-cli/src/render.rs +++ b/crates/bough-cli/src/render.rs @@ -192,6 +192,31 @@ impl Render for LangMutations { } } +#[derive(Facet)] +pub struct FileMutations(pub LanguageId, pub PathBuf, pub Vec); +impl Render for FileMutations { + fn markdown(&self) -> String { + format!( + "# Mutations in {}\n\n{} total\n\n{}", + self.1.display(), + self.2.len(), + self.2.iter().map(|m| format!("- {}", fmt_mutation_verbose(m))).collect::>().join("\n") + ) + } + + fn terse(&self) -> String { + self.2.iter().map(fmt_mutation_terse).collect::>().join("\n") + } + + fn verbose(&self) -> String { + self.2.iter().map(fmt_mutation_verbose).collect::>().join("\n") + } + + fn json(&self) -> String { + facet_json::to_string(self).unwrap() + } +} + impl Render for Config { fn markdown(&self) -> String { format!( -- knotmirror 0.0.1