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