Something went wrong. Try again.
A polyglot incremental mutation tester
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064use bough_core::{ LanguageId, Mutant, MutantKind, Mutation, PhaseOutcome, Point, Span, State, Status, Twig,};use bough_typed_hash::TypedHashable;use facet::Facet;
use crate::config::{Cli, Format};
fn strip_ansi(s: &str) -> String { let mut out = String::with_capacity(s.len()); let mut chars = s.chars(); while let Some(c) = chars.next() { if c == '\x1b' { for c in chars.by_ref() { if c == 'm' { break; } } } else { out.push(c); } } out}
pub(crate) fn render_table(rows: &[(Vec<String>, Vec<String>)]) -> String { if rows.is_empty() { return String::new(); } let headers = &rows[0].0; let header = headers .iter() .map(|h| format!(" {h} ")) .collect::<Vec<_>>() .join("|"); let sep = headers .iter() .map(|_| " --- ") .collect::<Vec<_>>() .join("|"); let body = rows .iter() .map(|(_, vals)| { vals.iter() .map(|v| format!(" {v} ")) .collect::<Vec<_>>() .join("|") }) .collect::<Vec<_>>() .join("\n"); format!("{header}\n{sep}\n{body}")}
pub(crate) const RESET: &str = "\x1b[0m";pub(crate) const BOLD: &str = "\x1b[1m";
pub(crate) const TITLE: &str = "\x1b[33m"; // yellowpub(crate) const STRING: &str = "\x1b[33m"; //yellow
pub(crate) const PATH: &str = "\x1b[34m"; // bluepub(crate) const WORKSPACE: &str = "\x1b[36m"; // cyanpub(crate) const MUTATION: &str = "\x1b[33m"; // yellowpub(crate) const MUTANT: &str = "\x1b[35m"; // magentapub(crate) const LANG: &str = "\x1b[35m"; //purple
pub(crate) const CAUGHT: &str = "\x1b[32m"; // greenpub(crate) const MISSED: &str = "\x1b[31m"; // redpub(crate) const TIMEOUT: &str = "\x1b[31m"; // redpub(crate) const NOT_RUN: &str = "\x1b[33m"; // yellow
pub trait Render { fn markdown(&self) -> String; fn terse(&self) -> String; fn verbose(&self) -> String; fn json(&self) -> String;
fn tabular(&self) -> (Vec<String>, Vec<String>) { panic!("Not impled for this struct") }
fn render(&self, cli: &Cli) -> String { let out = match cli.format { Format::Terse => self.terse(), Format::Verbose => self.verbose(), Format::Markdown => self.markdown(), Format::Json => self.json(), }; if cli.color() { out } else { strip_ansi(&out) } }}
#[derive(Facet)]pub struct Noop;
impl Render for Noop { fn markdown(&self) -> String { String::new() }
fn terse(&self) -> String { String::new() }
fn verbose(&self) -> String { String::new() }
fn json(&self) -> String { facet_json::to_string(self).unwrap() }}
impl Render for Status { fn markdown(&self) -> String { self.verbose() }
fn terse(&self) -> String { match self { Status::Caught | Status::CaughtByTests(_) => format!("{CAUGHT}caught{RESET}"), Status::Timeout => format!("{TIMEOUT}timeout{RESET}"), Status::Missed => format!("{MISSED}missed{RESET}"), } }
fn verbose(&self) -> String { match self { Status::Caught => format!("{CAUGHT}caught{RESET}"), Status::CaughtByTests(tests) => { let ids: Vec<_> = tests .iter() .map(|t| facet_json::to_string(t).unwrap()) .collect(); format!("{CAUGHT}caught by [{}]{RESET}", ids.join(", ")) } Status::Timeout => format!("{TIMEOUT}timeout{RESET}"), Status::Missed => format!("{MISSED}missed{RESET}"), } }
fn json(&self) -> String { facet_json::to_string(self).unwrap() }}
impl Render for Twig { fn markdown(&self) -> String { format!("{PATH}{}{RESET}", self.path().display()) }
fn terse(&self) -> String { self.markdown() }
fn verbose(&self) -> String { self.markdown() }
fn json(&self) -> String { format!(r#""{}""#, self.path().display()) }}
impl Render for Point { fn markdown(&self) -> String { format!("{}:{}", self.line() + 1, self.col() + 1) }
fn terse(&self) -> String { self.markdown() }
fn verbose(&self) -> String { self.markdown() }
fn json(&self) -> String { facet_json::to_string(self).unwrap() }}
impl Render for Span { fn markdown(&self) -> String { format!("{} - {}", self.start().markdown(), self.end().markdown()) }
fn terse(&self) -> String { self.markdown() }
fn verbose(&self) -> String { self.markdown() }
fn json(&self) -> String { facet_json::to_string(self).unwrap() }}
impl Render for State { fn markdown(&self) -> String { let m = self.mutation(); let hash = m.hash().expect("hash"); let status = match self.status() { Some(s) => s.markdown(), None => format!("{NOT_RUN}not run{RESET}"), }; format!( "{MUTATION}{hash}{RESET} {} {} {} {status} {} -> {STRING}{}{RESET}", m.mutant().lang().markdown(), m.mutant().twig().markdown(), m.mutant().span().markdown(), m.mutant().kind().markdown(), m.subst(), ) }
fn terse(&self) -> String { let m = self.mutation(); let hash = m.hash().expect("hash"); let status = match self.status() { Some(s) => s.terse(), None => format!("{NOT_RUN}not run{RESET}"), }; format!( "{MUTATION}{hash}{RESET} {} {} {} {status} {} -> {STRING}{}{RESET}", m.mutant().lang().terse(), m.mutant().twig().terse(), m.mutant().span().terse(), m.mutant().kind().terse(), m.subst(), ) }
fn verbose(&self) -> String { let m = self.mutation(); let hash = m.hash().expect("hash"); let status = match self.status() { Some(s) => s.verbose(), None => format!("{NOT_RUN}not run{RESET}"), }; format!( "{MUTATION}{hash}{RESET} {} {} {} {status} {} -> {STRING}{}{RESET}", m.mutant().lang().verbose(), m.mutant().twig().verbose(), m.mutant().span().verbose(), m.mutant().kind().verbose(), m.subst(), ) }
fn tabular(&self) -> (Vec<String>, Vec<String>) { let (mut headers, mut values) = self.mutation().tabular(); let status = match self.status() { Some(st) => st.markdown(), None => format!("{NOT_RUN}not run{RESET}"), }; headers.push("Status".into()); values.push(status); (headers, values) }
fn json(&self) -> String { facet_json::to_string(self).unwrap() }}
impl Render for Mutation { fn markdown(&self) -> String { let hash = self.hash().expect("hash"); format!( "{MUTATION}{hash}{RESET} {} -> {STRING}{}{RESET}", self.mutant().markdown(), self.subst(), ) }
fn terse(&self) -> String { let hash = self.hash().expect("hash"); format!( "{MUTATION}{hash}{RESET} {} -> {STRING}{}{RESET}", self.mutant().terse(), self.subst(), ) }
fn verbose(&self) -> String { let hash = self.hash().expect("hash"); format!( "{MUTATION}{hash}{RESET} {} -> {STRING}{}{RESET}", self.mutant().verbose(), self.subst(), ) }
fn tabular(&self) -> (Vec<String>, Vec<String>) { let hash = self.hash().expect("hash"); let (mut headers, mut values) = self.mutant().tabular(); headers.insert(0, "Hash".into()); values.insert(0, format!("`{hash}`")); headers.push("Subst".into()); values.push(format!("`{}`", self.subst())); (headers, values) }
fn json(&self) -> String { facet_json::to_string(self).unwrap() }}
impl Render for Mutant { fn markdown(&self) -> String { format!( "{} {} {} {}", self.lang().markdown(), self.twig().markdown(), self.span().markdown(), self.kind().markdown(), ) }
fn terse(&self) -> String { format!( "{} {} {} {}", self.lang().terse(), self.twig().terse(), self.span().terse(), self.kind().terse(), ) }
fn verbose(&self) -> String { format!( "{} {} {} {}", self.lang().verbose(), self.twig().verbose(), self.span().verbose(), self.kind().verbose(), ) }
fn tabular(&self) -> (Vec<String>, Vec<String>) { ( vec!["Lang".into(), "File".into(), "Span".into(), "Kind".into()], vec![ self.lang().markdown(), format!("{}", self.twig().path().display()), self.span().markdown(), format!("{:?}", self.kind()), ], ) }
fn json(&self) -> String { facet_json::to_string(self).unwrap() }}
impl Render for MutantKind { fn markdown(&self) -> String { format!("{MUTANT}{self:?}{RESET}") }
fn terse(&self) -> String { format!("{MUTANT}{self:?}{RESET}") }
fn verbose(&self) -> String { format!("{MUTANT}{self:?}{RESET}") }
fn json(&self) -> String { facet_json::to_string(self).unwrap() }}
impl Render for LanguageId { fn markdown(&self) -> String { self.verbose() }
fn terse(&self) -> String { format!( "{LANG}{}{RESET}", match self { LanguageId::Javascript => "js", LanguageId::Typescript => "ts", LanguageId::Python => "py", LanguageId::C => "c", LanguageId::Go => "go", LanguageId::Java => "java", LanguageId::CSharp => "cs", LanguageId::Rust => "rs", } ) }
fn verbose(&self) -> String { format!( "{LANG}{}{RESET}", match self { LanguageId::Javascript => "JavaScript", LanguageId::Typescript => "TypeScript", LanguageId::Python => "Python", LanguageId::C => "C", LanguageId::Go => "Go", LanguageId::Java => "Java", LanguageId::CSharp => "C#", LanguageId::Rust => "Rust", } ) }
fn json(&self) -> String { match self { LanguageId::Javascript => r#""js""#.to_string(), LanguageId::Typescript => r#""ts""#.to_string(), LanguageId::Python => r#""py""#.to_string(), LanguageId::C => r#""c""#.to_string(), LanguageId::Go => r#""go""#.to_string(), LanguageId::Java => r#""java""#.to_string(), LanguageId::CSharp => r#""cs""#.to_string(), LanguageId::Rust => r#""rs""#.to_string(), } }}
pub struct BenchmarkTimesInBase { pub init: Option<std::time::Duration>, pub reset: Option<std::time::Duration>, pub test: std::time::Duration,}
impl Render for BenchmarkTimesInBase { fn markdown(&self) -> String { let mut out = format!("{TITLE}# Benchmark Times (Base){RESET}\n"); if let Some(d) = self.init { out.push_str(&format!("\n- Init: {:.2}s", d.as_secs_f64())); } if let Some(d) = self.reset { out.push_str(&format!("\n- Reset: {:.2}s", d.as_secs_f64())); } out.push_str(&format!("\n- Test: {:.2}s", self.test.as_secs_f64())); out }
fn terse(&self) -> String { let mut parts = Vec::new(); if let Some(d) = self.init { parts.push(format!("init={:.2}s", d.as_secs_f64())); } if let Some(d) = self.reset { parts.push(format!("reset={:.2}s", d.as_secs_f64())); } parts.push(format!("test={:.2}s", self.test.as_secs_f64())); parts.join(" ") }
fn verbose(&self) -> String { let mut out = format!("{TITLE}Benchmark Times (Base){RESET}\n"); if let Some(d) = self.init { out.push_str(&format!("\n Init: {:.2}s", d.as_secs_f64())); } if let Some(d) = self.reset { out.push_str(&format!("\n Reset: {:.2}s", d.as_secs_f64())); } out.push_str(&format!("\n Test: {:.2}s", self.test.as_secs_f64())); out }
fn json(&self) -> String { let init = match self.init { Some(d) => format!("{:.3}", d.as_secs_f64()), None => "null".to_string(), }; let reset = match self.reset { Some(d) => format!("{:.3}", d.as_secs_f64()), None => "null".to_string(), }; format!( r#"{{"init_secs":{},"reset_secs":{},"test_secs":{:.3}}}"#, init, reset, self.test.as_secs_f64(), ) }}
fn phase_stdio_markdown_suffix(outcome: &PhaseOutcome) -> String { let stdout = String::from_utf8_lossy(outcome.stdout()); let stderr = String::from_utf8_lossy(outcome.stderr()); let mut out = String::new(); if !stdout.is_empty() { out.push_str(&format!("\n\n## stdout\n\n```\n{stdout}\n```")); } if !stderr.is_empty() { out.push_str(&format!("\n\n## stderr\n\n```\n{stderr}\n```")); } out}
fn phase_stdio_verbose_suffix(outcome: &PhaseOutcome) -> String { let stdout = String::from_utf8_lossy(outcome.stdout()); let stderr = String::from_utf8_lossy(outcome.stderr()); let mut out = String::new(); if !stdout.is_empty() { out.push_str(&format!("\n\n{TITLE}stdout{RESET}\n{stdout}")); } if !stderr.is_empty() { out.push_str(&format!("\n\n{TITLE}stderr{RESET}\n{stderr}")); } out}
fn phase_stdio_json_suffix(outcome: &PhaseOutcome) -> String { let stdout = String::from_utf8_lossy(outcome.stdout()); let stderr = String::from_utf8_lossy(outcome.stderr()); format!( r#","stdout":"{}","stderr":"{}""#, stdout .replace('\\', "\\\\") .replace('"', "\\\"") .replace('\n', "\\n"), stderr .replace('\\', "\\\\") .replace('"', "\\\"") .replace('\n', "\\n"), )}
impl Render for PhaseOutcome { fn markdown(&self) -> String { let header = match self { PhaseOutcome::Completed { exit_code, duration, .. } => format!( "- Exit: {exit_code}\n- Duration: {:.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)) }
fn terse(&self) -> String { match self { PhaseOutcome::Completed { exit_code, duration, .. } => format!("exit={exit_code} {:.2}s", duration.as_secs_f64()), PhaseOutcome::TimedOut { duration, .. } => { format!("TIMED_OUT {:.2}s", duration.as_secs_f64()) } } }
fn verbose(&self) -> String { let header = match self { PhaseOutcome::Completed { exit_code, duration, .. } => format!( "Exit: {exit_code}\nDuration: {:.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)) }
fn json(&self) -> String { let body = match self { PhaseOutcome::Completed { exit_code, duration, .. } => format!( r#"{{"status":"completed","exit_code":{exit_code},"duration_secs":{:.3}"#, duration.as_secs_f64(), ), PhaseOutcome::TimedOut { duration, .. } => format!( r#"{{"status":"timed_out","duration_secs":{:.3}"#, duration.as_secs_f64(), ), }; format!("{body}{}}}", phase_stdio_json_suffix(self)) }}
#[cfg(test)]mod tests { use super::*;
#[test] fn noop_markdown() { assert_eq!(Noop.markdown(), ""); }
#[test] fn noop_terse() { assert_eq!(Noop.terse(), ""); }
#[test] fn noop_verbose() { assert_eq!(Noop.verbose(), ""); }
#[test] fn noop_json() { assert_eq!(Noop.json(), "{}"); }
#[test] fn status_markdown() { let plain = Status::Caught .markdown() .replace(CAUGHT, "") .replace(RESET, ""); assert_eq!(plain, "caught"); }
#[test] fn status_terse() { let caught = Status::Caught.terse(); assert!(!caught.contains('\n')); let plain = caught.replace(CAUGHT, "").replace(RESET, ""); assert_eq!(plain, "caught");
let plain = Status::Missed .terse() .replace(MISSED, "") .replace(RESET, ""); assert_eq!(plain, "missed");
let plain = Status::Timeout .terse() .replace(TIMEOUT, "") .replace(RESET, ""); assert_eq!(plain, "timeout"); }
#[test] fn status_verbose() { let plain = Status::Missed .verbose() .replace(MISSED, "") .replace(RESET, ""); assert_eq!(plain, "missed"); }
#[test] fn status_json() { assert_eq!(Status::Caught.json(), r#""Caught""#); assert_eq!(Status::Missed.json(), r#""Missed""#); }
#[test] fn state_tabular() { let (headers, values) = make_state().tabular(); assert_eq!( headers, vec!["Hash", "Lang", "File", "Span", "Kind", "Subst", "Status"] ); assert_eq!(headers.len(), values.len()); assert!(values[2].contains("src/main.ts")); }
fn make_state() -> State { State::new(make_mutation()) }
#[test] fn state_markdown() { let out = make_state().markdown(); let plain = out.replace(NOT_RUN, "").replace(RESET, ""); assert!(plain.contains("not run")); assert!(plain.contains("src/main.ts")); }
#[test] fn state_terse() { let out = make_state().terse(); assert!(!out.contains('\n')); }
#[test] fn state_verbose() { let out = make_state().verbose(); let plain = out.replace(NOT_RUN, "").replace(RESET, ""); assert!(plain.contains("not run")); }
#[test] fn state_json() { let out = make_state().json(); assert!(out.starts_with('{')); assert!(out.contains("mutation")); }
fn make_mutation() -> Mutation { bough_core::MutationIter::new(&make_mutant()) .next() .unwrap() }
fn make_mutant() -> Mutant { Mutant::new( LanguageId::Typescript, Twig::new("src/main.ts".into()).unwrap(), MutantKind::StatementBlock, Span::new(Point::new(0, 0, 0), Point::new(2, 3, 20)), Span::new(Point::new(0, 0, 0), Point::new(2, 3, 20)), ) }
#[test] fn mutation_markdown() { let m = make_mutation(); let out = m.markdown(); assert!(out.contains(m.subst())); assert!(out.contains("src/main.ts")); }
#[test] fn mutation_terse() { let out = make_mutation().terse(); assert!(!out.contains('\n')); }
#[test] fn mutation_verbose() { let m = make_mutation(); let out = m.verbose(); assert!(out.contains(m.subst())); }
#[test] fn mutation_json() { let out = make_mutation().json(); assert!(out.starts_with('{')); assert!(out.contains("subst")); }
#[test] fn mutation_tabular() { let (headers, values) = make_mutation().tabular(); assert_eq!( headers, vec!["Hash", "Lang", "File", "Span", "Kind", "Subst"] ); assert_eq!(headers.len(), values.len()); assert!(values[2].contains("src/main.ts")); }
#[test] fn mutant_markdown() { let plain = make_mutant() .markdown() .replace(PATH, "") .replace(MUTANT, "") .replace(LANG, "") .replace(RESET, ""); assert_eq!(plain, "TypeScript src/main.ts 1:1 - 3:4 StatementBlock"); }
#[test] fn mutant_terse() { let out = make_mutant().terse(); assert!(!out.contains('\n')); }
#[test] fn mutant_verbose() { let plain = make_mutant() .verbose() .replace(PATH, "") .replace(MUTANT, "") .replace(LANG, "") .replace(RESET, ""); assert_eq!(plain, "TypeScript src/main.ts 1:1 - 3:4 StatementBlock"); }
#[test] fn mutant_json() { let json = make_mutant().json(); assert!(json.starts_with('{')); assert!(json.contains(r#""lang":"ts""#)); }
#[test] fn mutant_tabular() { let (headers, values) = make_mutant().tabular(); assert_eq!(headers, vec!["Lang", "File", "Span", "Kind"]); assert_eq!(headers.len(), values.len()); assert!(values[1].contains("src/main.ts")); }
#[test] fn twig_markdown() { let twig = Twig::new("src/main.ts".into()).unwrap(); let plain = twig.markdown().replace(PATH, "").replace(RESET, ""); assert_eq!(plain, "src/main.ts"); }
#[test] fn twig_terse() { let twig = Twig::new("src/main.ts".into()).unwrap(); assert!(!twig.terse().contains('\n')); }
#[test] fn twig_verbose() { let twig = Twig::new("src/main.ts".into()).unwrap(); let plain = twig.verbose().replace(PATH, "").replace(RESET, ""); assert_eq!(plain, "src/main.ts"); }
#[test] fn twig_json() { let twig = Twig::new("src/main.ts".into()).unwrap(); assert_eq!(twig.json(), r#""src/main.ts""#); }
#[test] fn point_markdown() { assert_eq!(Point::new(0, 0, 0).markdown(), "1:1"); assert_eq!(Point::new(9, 4, 100).markdown(), "10:5"); }
#[test] fn point_terse() { assert_eq!(Point::new(0, 0, 0).terse(), "1:1"); }
#[test] fn point_verbose() { assert_eq!(Point::new(0, 0, 0).verbose(), "1:1"); }
#[test] fn point_json() { assert_eq!( Point::new(0, 5, 10).json(), r#"{"line":0,"col":5,"byte":10}"# ); }
#[test] fn span_markdown() { let span = Span::new(Point::new(0, 0, 0), Point::new(2, 3, 20)); assert_eq!(span.markdown(), "1:1 - 3:4"); }
#[test] fn span_terse() { let span = Span::new(Point::new(0, 0, 0), Point::new(2, 3, 20)); assert_eq!(span.terse(), "1:1 - 3:4"); }
#[test] fn span_verbose() { let span = Span::new(Point::new(0, 0, 0), Point::new(2, 3, 20)); assert_eq!(span.verbose(), "1:1 - 3:4"); }
#[test] fn span_json() { let span = Span::new(Point::new(0, 0, 0), Point::new(2, 3, 20)); assert_eq!( span.json(), r#"{"start":{"line":0,"col":0,"byte":0},"end":{"line":2,"col":3,"byte":20}}"# ); }
#[test] fn mutant_kind_markdown() { use bough_core::MutantKind; let plain = MutantKind::StatementBlock .markdown() .replace(MUTANT, "") .replace(RESET, ""); assert_eq!(plain, "StatementBlock"); }
#[test] fn mutant_kind_terse() { use bough_core::MutantKind; let out = MutantKind::Condition.terse(); assert!(!out.contains('\n')); let plain = out.replace(MUTANT, "").replace(RESET, ""); assert_eq!(plain, "Condition"); }
#[test] fn mutant_kind_verbose() { use bough_core::MutantKind; let plain = MutantKind::DictDecl .verbose() .replace(MUTANT, "") .replace(RESET, ""); assert_eq!(plain, "DictDecl"); }
#[test] fn mutant_kind_json() { use bough_core::MutantKind; assert_eq!(MutantKind::StatementBlock.json(), r#""StatementBlock""#); }
#[test] fn language_id_markdown() { let js = LanguageId::Javascript .markdown() .replace(LANG, "") .replace(RESET, ""); let ts = LanguageId::Typescript .markdown() .replace(LANG, "") .replace(RESET, ""); assert_eq!(js, "JavaScript"); assert_eq!(ts, "TypeScript"); let py = LanguageId::Python .markdown() .replace(LANG, "") .replace(RESET, ""); assert_eq!(py, "Python"); }
#[test] fn language_id_terse() { let js = LanguageId::Javascript .terse() .replace(LANG, "") .replace(RESET, ""); let ts = LanguageId::Typescript .terse() .replace(LANG, "") .replace(RESET, ""); assert_eq!(js, "js"); assert_eq!(ts, "ts"); let py = LanguageId::Python .terse() .replace(LANG, "") .replace(RESET, ""); assert_eq!(py, "py"); }
#[test] fn language_id_verbose() { let js = LanguageId::Javascript .verbose() .replace(LANG, "") .replace(RESET, ""); let ts = LanguageId::Typescript .verbose() .replace(LANG, "") .replace(RESET, ""); assert_eq!(js, "JavaScript"); assert_eq!(ts, "TypeScript"); let py = LanguageId::Python .verbose() .replace(LANG, "") .replace(RESET, ""); assert_eq!(py, "Python"); }
#[test] fn language_id_json() { assert_eq!(LanguageId::Javascript.json(), r#""js""#); assert_eq!(LanguageId::Typescript.json(), r#""ts""#); assert_eq!(LanguageId::Python.json(), r#""py""#); }
fn make_benchmark() -> BenchmarkTimesInBase { BenchmarkTimesInBase { init: Some(std::time::Duration::from_millis(1500)), reset: None, test: std::time::Duration::from_millis(2000), } }
#[test] fn benchmark_markdown() { let plain = make_benchmark() .markdown() .replace(TITLE, "") .replace(RESET, ""); assert!(plain.contains("Init: 1.50s")); assert!(!plain.contains("Reset")); assert!(plain.contains("Test: 2.00s")); }
#[test] fn benchmark_terse() { let out = make_benchmark().terse(); assert!(!out.contains('\n')); assert_eq!(out, "init=1.50s test=2.00s"); }
#[test] fn benchmark_verbose() { let plain = make_benchmark() .verbose() .replace(TITLE, "") .replace(RESET, ""); assert!(plain.contains("Init: 1.50s")); assert!(plain.contains("Test: 2.00s")); }
#[test] fn benchmark_json() { let out = make_benchmark().json(); assert!(out.contains(r#""reset_secs":null"#)); assert!(out.contains(r#""test_secs":2.000"#)); }
fn make_phase_outcome() -> PhaseOutcome { PhaseOutcome::Completed { exit_code: 0, duration: std::time::Duration::from_millis(1234), stdout: b"hello\n".to_vec(), stderr: vec![], } }
#[test] fn phase_outcome_markdown() { let out = make_phase_outcome().markdown(); assert!(out.contains("Exit: 0")); assert!(out.contains("```\nhello\n\n```")); }
#[test] fn phase_outcome_terse() { let out = make_phase_outcome().terse(); assert!(!out.contains('\n')); assert!(out.contains("exit=0")); assert!(out.contains("1.23s")); }
#[test] fn phase_outcome_verbose() { let out = make_phase_outcome().verbose(); assert!(out.contains("Exit: 0")); assert!(out.contains("hello")); }
#[test] fn phase_outcome_json() { let out = make_phase_outcome().json(); assert!(out.contains(r#""exit_code":0"#)); assert!(out.contains(r#""status":"completed""#)); }}