Remove 'seed' arg from 'with_project' to FinishedTests event

Also polish a bit the output of tests, move test result to stdout to allow filtering out warnings by redirecting stderr to /dev/null.
This commit is contained in:
KtorZ
2024-03-04 18:43:39 +01:00
parent c9dd281b45
commit df3baa082e
10 changed files with 76 additions and 92 deletions

View File

@@ -347,7 +347,7 @@ where
.collect();
self.event_listener
.handle_event(Event::FinishedTests { tests });
.handle_event(Event::FinishedTests { seed, tests });
if !errors.is_empty() {
Err(errors)

View File

@@ -37,6 +37,7 @@ pub enum Event {
},
RunningTests,
FinishedTests {
seed: u32,
tests: Vec<TestResult<UntypedExpr>>,
},
WaitingForBuildDirLock,
@@ -170,7 +171,7 @@ impl EventListener for Terminal {
"...".if_supports_color(Stderr, |s| s.bold())
);
}
Event::FinishedTests { tests } => {
Event::FinishedTests { seed, tests } => {
let (max_mem, max_cpu, max_iter) = find_max_execution_units(&tests);
for (module, results) in &group_by_module(&tests) {
@@ -185,10 +186,22 @@ impl EventListener for Terminal {
.collect::<Vec<String>>()
.join("\n");
let summary = fmt_test_summary(results, true);
let seed_info = if results
.iter()
.any(|t| matches!(t, TestResult::PropertyTestResult { .. }))
{
format!(
"with {opt}={seed}",
opt = "--seed".if_supports_color(Stderr, |s| s.bold()),
seed = format!("{seed}").if_supports_color(Stderr, |s| s.bold())
)
} else {
String::new()
};
eprintln!(
"{}\n",
let summary = format!("{}{}", seed_info, fmt_test_summary(results, true));
println!(
"{}",
pretty::indent(
&pretty::open_box(&title, &tests, &summary, |border| border
.if_supports_color(Stderr, |s| s.bright_black())
@@ -319,19 +332,20 @@ fn fmt_test(
}) = result
{
test = format!(
"{test}\n{}",
pretty::open_box(
&pretty::style_if(styled, "counterexample".to_string(), |s| s
.if_supports_color(Stderr, |s| s.red())
.if_supports_color(Stderr, |s| s.bold())
.to_string()),
&Formatter::new()
.expr(counterexample, false)
.to_pretty_string(70),
"",
|s| s.red().to_string()
)
)
"{test}\n{}\n{}\n",
"× counterexample"
.if_supports_color(Stderr, |s| s.red())
.if_supports_color(Stderr, |s| s.bold()),
&Formatter::new()
.expr(counterexample, false)
.to_pretty_string(60)
.lines()
.map(|line| {
format!("{} {}", "".if_supports_color(Stderr, |s| s.red()), line)
})
.collect::<Vec<String>>()
.join("\n")
);
}
// Traces

View File

@@ -75,12 +75,7 @@ pub fn default_filter(evt: &Event) -> bool {
}
}
pub fn with_project<A>(
directory: Option<&Path>,
seed: u32,
deny: bool,
mut action: A,
) -> miette::Result<()>
pub fn with_project<A>(directory: Option<&Path>, deny: bool, mut action: A) -> miette::Result<()>
where
A: FnMut(&mut Project<Terminal>) -> Result<(), Vec<crate::error::Error>>,
{
@@ -113,23 +108,16 @@ where
err.report()
}
eprintln!(
"{}",
Summary {
warning_count,
error_count: errs.len(),
}
);
if errs.iter().any(|e| matches!(e, Error::TestFailure { .. })) {
if !errs.iter().any(|e| matches!(e, Error::TestFailure { .. })) {
eprintln!(
" {}══╤══\n{} ╰─▶ use {} {} to replay",
if errs.len() > 1 { "" } else { "" },
if errs.len() > 1 { " " } else { "" },
"--seed".if_supports_color(Stderr, |s| s.bold()),
format!("{seed}").if_supports_color(Stderr, |s| s.bold())
"{}",
Summary {
warning_count,
error_count: errs.len(),
}
);
}
return Err(ExitFailure::into_report());
}
@@ -162,7 +150,6 @@ where
pub fn watch_project<F, A>(
directory: Option<&Path>,
filter: F,
seed: u32,
debounce: u32,
mut action: A,
) -> miette::Result<()>
@@ -228,13 +215,14 @@ where
// If we have an event that survived the filter, then we can construct the project and invoke the action
if latest.is_some() {
print!("{esc}c", esc = 27 as char);
println!(
eprint!("{esc}c", esc = 27 as char);
eprintln!(
"{} ...",
" Watching"
.if_supports_color(Stderr, |s| s.bold())
.if_supports_color(Stderr, |s| s.purple()),
);
with_project(directory, seed, false, &mut action).unwrap_or(())
with_project(directory, false, &mut action).unwrap_or(())
}
}
}