|
| 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