Update nice_panic macro
This commit is contained in:
parent
67b07dfd72
commit
8b7ed96e15
18
src/util.rs
18
src/util.rs
@ -2,18 +2,28 @@
|
|||||||
/// 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) => {
|
||||||
{
|
{
|
||||||
eprintln!($fmt);
|
if cfg!(test) || cfg!(debug_assertions) {
|
||||||
std::process::exit(1);
|
panic!($fmt);
|
||||||
|
} else {
|
||||||
|
eprintln!($fmt);
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
($fmt:expr, $($arg:tt)*) => {
|
($fmt:expr, $($arg:tt)*) => {
|
||||||
{
|
{
|
||||||
eprintln!($fmt, $($arg)*);
|
if cfg!(test) || cfg!(debug_assertions) {
|
||||||
std::process::exit(1);
|
panic!($fmt, $($arg)*);
|
||||||
|
} else {
|
||||||
|
eprintln!($fmt, $($arg)*);
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user