diff options
| author | David Lönnhager <david.l@mullvad.net> | 2024-09-21 13:49:26 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2024-09-23 11:45:59 +0200 |
| commit | 98a05b37d1a67444626cba1513b86ec95bb53c40 (patch) | |
| tree | 102578f3e66d5302c39fef2ce120ffb0b86e15dc /test | |
| parent | 77f581d198634b82b5d4f5477b3b3e9e5bb9cd9c (diff) | |
| download | mullvadvpn-98a05b37d1a67444626cba1513b86ec95bb53c40.tar.xz mullvadvpn-98a05b37d1a67444626cba1513b86ec95bb53c40.zip | |
Add timestamp to test outcome logs
Diffstat (limited to 'test')
| -rw-r--r-- | test/test-manager/src/logging.rs | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/test/test-manager/src/logging.rs b/test/test-manager/src/logging.rs index ce7477cd69..860cafd0a5 100644 --- a/test/test-manager/src/logging.rs +++ b/test/test-manager/src/logging.rs @@ -191,15 +191,21 @@ impl TestResult { } } +macro_rules! println_with_time { + ($fmt:tt$(, $($args:tt)*)?) => { + println!(concat!("[{}] ", $fmt), chrono::Local::now(), $($($args)*)?) + }; +} + impl TestOutput { pub fn print(&self) { match &self.result { TestResult::Pass => { - println!("{}", format!("TEST {} SUCCEEDED!", self.test_name).green()); + println_with_time!("{}", format!("TEST {} SUCCEEDED!", self.test_name).green()); return; } TestResult::Fail(e) => { - println!( + println_with_time!( "{}", format!( "TEST {} RETURNED ERROR: {}", @@ -210,7 +216,7 @@ impl TestOutput { ); } TestResult::Panic(panic_msg) => { - println!( + println_with_time!( "{}", format!( "TEST {} PANICKED WITH MESSAGE: {}", @@ -222,12 +228,12 @@ impl TestOutput { } } - println!("{}", format!("TEST {} HAD LOGS:", self.test_name).red()); + println_with_time!("{}", format!("TEST {} HAD LOGS:", self.test_name).red()); match &self.log_output { Some(log) => { match &log.settings_json { - Ok(settings) => println!("settings.json: {}", settings), - Err(e) => println!("Could not get settings.json: {}", e), + Ok(settings) => println_with_time!("settings.json: {}", settings), + Err(e) => println_with_time!("Could not get settings.json: {}", e), } match &log.log_files { @@ -235,30 +241,34 @@ impl TestOutput { for log in log_files { match log { Ok(log) => { - println!("Log {}:\n{}", log.name.to_str().unwrap(), log.content) + println_with_time!( + "Log {}:\n{}", + log.name.to_str().unwrap(), + log.content + ) } - Err(e) => println!("Could not get log: {}", e), + Err(e) => println_with_time!("Could not get log: {}", e), } } } - Err(e) => println!("Could not get logs: {}", e), + Err(e) => println_with_time!("Could not get logs: {}", e), } } - None => println!("Missing logs for {}", self.test_name), + None => println_with_time!("Missing logs for {}", self.test_name), } - println!( + println_with_time!( "{}", format!("TEST RUNNER {} HAD RUNTIME OUTPUT:", self.test_name).red() ); if self.error_messages.is_empty() { - println!("<no output>"); + println_with_time!("<no output>"); } else { for msg in &self.error_messages { - println!("{}", msg); + println_with_time!("{}", msg); } } - println!("{}", format!("TEST {} END OF OUTPUT", self.test_name).red()); + println_with_time!("{}", format!("TEST {} END OF OUTPUT", self.test_name).red()); } } |
