Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit 216a4e0

Browse files
author
Hendrik van Antwerpen
committed
Cleanup file status logging
1 parent 2db4685 commit 216a4e0

File tree

1 file changed

+18
-22
lines changed
  • tree-sitter-stack-graphs/src/cli

1 file changed

+18
-22
lines changed

tree-sitter-stack-graphs/src/cli/test.rs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use anyhow::Context as _;
1010
use clap::ArgEnum;
1111
use clap::Args;
1212
use clap::ValueHint;
13-
use colored::Colorize as _;
1413
use stack_graphs::arena::Handle;
1514
use stack_graphs::graph::File;
1615
use stack_graphs::graph::StackGraph;
@@ -34,6 +33,8 @@ use crate::LoadError;
3433
use crate::NoCancellation;
3534
use crate::StackGraphLanguage;
3635

36+
use super::util::FileStatusLogger;
37+
3738
/// Flag to control output
3839
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ArgEnum)]
3940
pub enum OutputMode {
@@ -206,8 +207,10 @@ impl TestArgs {
206207
test_path: &Path,
207208
loader: &mut Loader,
208209
) -> anyhow::Result<TestResult> {
210+
let mut file_status = FileStatusLogger::new(test_path, !self.quiet);
211+
209212
if self.show_skipped && test_path.extension().map_or(false, |e| e == "skip") {
210-
println!("{}: {}", test_path.display(), "skipped".yellow());
213+
file_status.warn("skipped")?;
211214
return Ok(TestResult::new());
212215
}
213216

@@ -220,9 +223,7 @@ impl TestArgs {
220223
};
221224
let source = file_reader.get(test_path)?;
222225

223-
if !self.quiet {
224-
print!("{}: ", test_path.display());
225-
}
226+
file_status.processing()?;
226227

227228
let default_fragment_path = test_path.strip_prefix(test_root).unwrap();
228229
let mut test = Test::from_source(&test_path, &source, default_fragment_path)?;
@@ -269,7 +270,7 @@ impl TestArgs {
269270
}
270271
}
271272
let result = test.run(cancellation_flag)?;
272-
let success = self.handle_result(test_path, &result)?;
273+
let success = self.handle_result(&result, &mut file_status)?;
273274
if self.output_mode.test(!success) {
274275
let files = test.fragments.iter().map(|f| f.file).collect::<Vec<_>>();
275276
self.save_output(
@@ -314,25 +315,20 @@ impl TestArgs {
314315
}
315316
}
316317

317-
fn handle_result(&self, test_path: &Path, result: &TestResult) -> anyhow::Result<bool> {
318+
fn handle_result(
319+
&self,
320+
result: &TestResult,
321+
file_status: &mut FileStatusLogger,
322+
) -> anyhow::Result<bool> {
318323
let success = result.failure_count() == 0;
319324
if success {
320-
if !self.quiet {
321-
println!("{}", "success".green());
322-
}
325+
file_status.ok("success")?;
323326
} else {
324-
if self.quiet {
325-
print!("{}: ", test_path.display());
326-
}
327-
println!(
328-
"{}",
329-
format!(
330-
"{}/{} assertions failed",
331-
result.failure_count(),
332-
result.count(),
333-
)
334-
.red()
335-
);
327+
file_status.error(&format!(
328+
"{}/{} assertions failed",
329+
result.failure_count(),
330+
result.count(),
331+
))?;
336332
}
337333
if !success && !self.hide_failure_errors {
338334
for failure in result.failures_iter() {

0 commit comments

Comments
 (0)