Skip to content

Commit 9b33aab

Browse files
committed
Add debug status emitter
1 parent 848aa1f commit 9b33aab

File tree

2 files changed

+112
-2
lines changed

2 files changed

+112
-2
lines changed

src/status_emitter.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ use std::{
2828
time::Duration,
2929
};
3030

31+
pub mod debug;
32+
3133
/// A generic way to handle the output of this crate.
3234
pub trait StatusEmitter: Sync + RefUnwindSafe {
3335
/// Invoked the moment we know a test will later be run.
@@ -217,14 +219,26 @@ impl Text {
217219
}
218220
};
219221

220-
#[derive(Debug)]
221222
struct Thread {
222223
parent: usize,
223224
spinner: ProgressBar,
224225
/// Used for sanity assertions only
225226
done: bool,
226227
}
227228

229+
impl Debug for Thread {
230+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
231+
f.debug_struct("Thread")
232+
.field("parent", &self.parent)
233+
.field(
234+
"spinner",
235+
&format_args!("{}: {}", self.spinner.prefix(), self.spinner.message()),
236+
)
237+
.field("done", &self.done)
238+
.finish()
239+
}
240+
}
241+
228242
struct ProgressHandler {
229243
threads: Vec<Option<Thread>>,
230244
aborted: bool,
@@ -367,7 +381,7 @@ impl Text {
367381
assert_eq!(
368382
Some(progress.spinner.position()),
369383
progress.spinner.length(),
370-
"{:#?}",
384+
"{:?}",
371385
self.threads
372386
);
373387
progress.spinner.finish();

src/status_emitter/debug.rs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
//! A debug emitter for when things get stuck. Mostly useful for debugging of ui_test itself
2+
3+
use std::path::{Path, PathBuf};
4+
5+
use crate::Error;
6+
7+
/// Very verbose status emitter
8+
pub struct StatusEmitter;
9+
10+
impl super::StatusEmitter for StatusEmitter {
11+
fn register_test(&self, path: PathBuf) -> Box<dyn super::TestStatus + 'static> {
12+
eprintln!("START {}", path.display());
13+
Box::new(TestStatus(path, String::new()))
14+
}
15+
16+
fn finalize(
17+
&self,
18+
failed: usize,
19+
succeeded: usize,
20+
ignored: usize,
21+
filtered: usize,
22+
aborted: bool,
23+
) -> Box<dyn super::Summary> {
24+
eprintln!("{failed}, {succeeded}, {ignored}, {filtered}, {aborted}");
25+
Box::new(Summary)
26+
}
27+
}
28+
29+
struct Summary;
30+
31+
impl super::Summary for Summary {
32+
fn test_failure(&mut self, status: &dyn super::TestStatus, errors: &Vec<Error>) {
33+
eprintln!(
34+
"FAILED: {} ({})",
35+
status.path().display(),
36+
status.revision()
37+
);
38+
eprintln!("{errors:#?}");
39+
}
40+
}
41+
42+
struct TestStatus(PathBuf, String);
43+
44+
impl super::TestStatus for TestStatus {
45+
fn for_revision(
46+
&self,
47+
revision: &str,
48+
_style: super::RevisionStyle,
49+
) -> Box<dyn super::TestStatus> {
50+
eprintln!(
51+
"REVISION {}: {} (old: {})",
52+
self.0.display(),
53+
revision,
54+
self.1
55+
);
56+
Box::new(TestStatus(self.0.clone(), revision.to_string()))
57+
}
58+
59+
fn for_path(&self, path: &Path) -> Box<dyn super::TestStatus> {
60+
eprintln!(
61+
"PATH {} (old: {} ({}))",
62+
path.display(),
63+
self.0.display(),
64+
self.1
65+
);
66+
Box::new(TestStatus(path.to_owned(), String::new()))
67+
}
68+
69+
fn failed_test<'a>(
70+
&'a self,
71+
cmd: &'a str,
72+
stderr: &'a [u8],
73+
stdout: &'a [u8],
74+
) -> Box<dyn std::fmt::Debug + 'a> {
75+
eprintln!("failed {} ({})", self.0.display(), self.1);
76+
eprintln!("{cmd}");
77+
eprintln!("{}", std::str::from_utf8(stderr).unwrap());
78+
eprintln!("{}", std::str::from_utf8(stdout).unwrap());
79+
eprintln!();
80+
Box::new(())
81+
}
82+
83+
fn path(&self) -> &Path {
84+
&self.0
85+
}
86+
87+
fn revision(&self) -> &str {
88+
&self.1
89+
}
90+
}
91+
92+
impl Drop for TestStatus {
93+
fn drop(&mut self) {
94+
eprintln!("DONE {} ({})", self.0.display(), self.1);
95+
}
96+
}

0 commit comments

Comments
 (0)