I'm following this workaround to get info!, log! etc working on tests:
https://stackoverflow.com/a/67105052/5884503
This is what I did. I created proxy functions to be imported just in the case we're testing, like this:
#[cfg(not(test))]
use log::{info, error}; // Use log crate when building application
#[cfg(test)]
use crate::{info, error}; // Workaround to use prinltn! for logs.
Here it is:
#[macro_export]
macro_rules! info {
(target: $target:expr, $($arg:tt)*) => { println!("target: {}, info: {}", $target, $($arg),*) };
($($arg:tt)*) => { println!("info: {}", $($arg),*) };
}
#[macro_export]
macro_rules! error {
(target: $target:expr, $($arg:tt)*) => { printn!("target: {}, info: {}", $target, $($arg),*) };
($($arg:tt)*) => { println!("error: {}", $($arg),*) };
}
Then I call like this:
error!("Unauthorized message has authentication header but WwwAuthenticate fails to parse. RTSP Message: {:?}", message);
but I get:
error: expected expression, found `,`
--> src/rtsp_machine.rs:440:96
|
440 | "Unauthorized message has no AuthenticationInfo header. RTSP Message: {:?}",
| ^ expected expression
Something is wrong with the repetition in the macro argument but I don't know what exactly