From 8b7ed96e15b4f0e31a1ad0fe37b40b02f2269620 Mon Sep 17 00:00:00 2001 From: Daniel M Date: Fri, 11 Feb 2022 01:19:34 +0100 Subject: [PATCH] Update nice_panic macro --- src/util.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/util.rs b/src/util.rs index 7da8060..18e7b6b 100644 --- a/src/util.rs +++ b/src/util.rs @@ -2,18 +2,28 @@ /// 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 /// end user. +/// When running tests or running in debug mode, panic is used to ensure the tests working +/// correctly. #[macro_export] macro_rules! nice_panic { ($fmt:expr) => { { - eprintln!($fmt); - std::process::exit(1); + if cfg!(test) || cfg!(debug_assertions) { + panic!($fmt); + } else { + eprintln!($fmt); + std::process::exit(1); + } } }; ($fmt:expr, $($arg:tt)*) => { { - eprintln!($fmt, $($arg)*); - std::process::exit(1); + if cfg!(test) || cfg!(debug_assertions) { + panic!($fmt, $($arg)*); + } else { + eprintln!($fmt, $($arg)*); + std::process::exit(1); + } } }; }