diff --git a/src/log.rs b/src/log.rs index 429df2995..8d1f4f914 100644 --- a/src/log.rs +++ b/src/log.rs @@ -68,18 +68,6 @@ impl Ord for Level { #[macro_export(local_inner_macros)] macro_rules! log { - (target: $target:expr, $lvl:expr, $message:expr) => ({ - let lvl = $lvl; - //if lvl <= $crate::STATIC_MAX_LEVEL && lvl <= $crate::max_level() { - // ensure that $message is a valid format string literal - let _ = __log_format_args!($message); - $crate::log::__private_api_log_lit( - $message, - lvl, - &($target, __log_module_path!(), __log_file!(), __log_line!()), - ); - //} - }); (target: $target:expr, $lvl:expr, $($arg:tt)+) => ({ let lvl = $lvl; //if lvl <= $crate::STATIC_MAX_LEVEL && lvl <= $crate::max_level() { @@ -184,6 +172,8 @@ pub fn __private_api_log_lit( _level: Level, &(_target, _module_path, _file, _line): &(&str, &'static str, &'static str, u32), ) { + #[cfg(test)] + LOGGED.with(|logged| logged.borrow_mut().push(message.to_owned())); eprintln!("{}", message); } @@ -237,20 +227,39 @@ pub fn __private_api_log_lit( crate::native::ios::log(message); } +#[cfg(test)] +thread_local! { + /// Every message the desktop logger was given, so `test_logs` can check them. + static LOGGED: std::cell::RefCell> = std::cell::RefCell::new(Vec::new()); +} + #[test] fn test_logs() { + let value = 1; + trace!("info"); trace!("info: {}", 1); + trace!("info: {value}"); debug!("info"); debug!("info: {}", 1); + debug!("info: {value}"); info!("info"); info!("info: {}", 1); + info!("info: {value}"); warn!("info"); warn!("info: {}", 1); + warn!("info: {value}"); error!("info"); error!("info: {}", 1); + error!("info: {value}"); + + info!("{{value}}"); + + let mut expected = ["info", "info: 1", "info: 1"].repeat(5); + expected.push("{value}"); + LOGGED.with(|logged| assert_eq!(*logged.borrow(), expected)); }