Update nice_panic macro

This commit is contained in:
Daniel M 2022-02-11 01:19:34 +01:00
parent 67b07dfd72
commit 8b7ed96e15

View File

@ -2,19 +2,29 @@
/// works like panic, but doesn't show the additional information that panic adds. Those can be /// works like panic, but doesn't show the additional information that panic adds. Those can be
/// interesting for debugging, but don't look that great when building a release executable for an /// interesting for debugging, but don't look that great when building a release executable for an
/// end user. /// end user.
/// When running tests or running in debug mode, panic is used to ensure the tests working
/// correctly.
#[macro_export] #[macro_export]
macro_rules! nice_panic { macro_rules! nice_panic {
($fmt:expr) => { ($fmt:expr) => {
{ {
if cfg!(test) || cfg!(debug_assertions) {
panic!($fmt);
} else {
eprintln!($fmt); eprintln!($fmt);
std::process::exit(1); std::process::exit(1);
} }
}
}; };
($fmt:expr, $($arg:tt)*) => { ($fmt:expr, $($arg:tt)*) => {
{ {
if cfg!(test) || cfg!(debug_assertions) {
panic!($fmt, $($arg)*);
} else {
eprintln!($fmt, $($arg)*); eprintln!($fmt, $($arg)*);
std::process::exit(1); std::process::exit(1);
} }
}
}; };
} }