Commit 2c0d5880 authored by Raphaël Gomès's avatar Raphaël Gomès
Browse files

Don't print if the current thread is panicking

parent 7f78d0476cb9
......@@ -53,6 +53,9 @@ fn inner_timed(_attr_ts: TokenStream, fn_ts: TokenStream) -> TokenStream {
::micro_timer::scopeguard::guard_on_success(
__micro_timer_instant,
|timer| {
if ::std::thread::panicking() {
return
}
crate::log::trace!(
"Duration of `{}`: {:?}",
#original_func_name,
......@@ -102,6 +105,9 @@ mod tests {
::micro_timer::scopeguard::guard_on_success(
__micro_timer_instant,
|timer| {
if ::std::thread::panicking() {
return
}
crate::log::trace!(
"Duration of `{}`: {:?}",
"my_super_function",
......
......@@ -43,4 +43,17 @@ fn test_behavior() {
assert_eq!(LOGGER.called.load(Ordering::Relaxed), 0);
thing();
assert_eq!(LOGGER.called.load(Ordering::Relaxed), 1);
#[timed]
fn thing_panicking() {
panic!("at the disco")
}
assert_eq!(LOGGER.called.load(Ordering::Relaxed), 1);
let res = std::panic::catch_unwind(|| {
thing_panicking();
});
assert!(res.is_err());
// Should not print anything if it panics
assert_eq!(LOGGER.called.load(Ordering::Relaxed), 1);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment