From 97cdfd33ddaab01970b07c077f6de80d2bbea157 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Wed, 26 Jan 2022 11:30:48 +0100 Subject: [PATCH] Add more debug assertion macros --- nih_plug/src/debug.rs | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/nih_plug/src/debug.rs b/nih_plug/src/debug.rs index 5d3ccf80..f9488c1f 100644 --- a/nih_plug/src/debug.rs +++ b/nih_plug/src/debug.rs @@ -26,8 +26,8 @@ macro_rules! nih_log { ); } -/// A `debug_assert!()` analogue that prints the error instead with line number information instead -/// of panicking. +/// A `debug_assert!()` analogue that prints the error with line number information instead of +/// panicking. /// /// TODO: Detect if we're running under a debugger, and trigger a break if we are macro_rules! nih_debug_assert { @@ -42,3 +42,33 @@ macro_rules! nih_debug_assert { } ); } + +/// A `debug_assert_eq!()` analogue that prints the error with line number information instead of +/// panicking. +macro_rules! nih_debug_assert_eq { + ($left:expr, $right:expr) => ( + if cfg!(debug_assertions) && $left != $right { + nih_log!(concat!("Debug assertion failed: ", stringify!($left), " != ", stringify!($right))); + } + ); + (left:expr, $right:expr, $format:expr $(, $arg:tt)*) => ( + if cfg!(debug_assertions) && $left != $right { + nih_log!(concat!("Debug assertion failed: ", stringify!($left), " != ", stringify!($right), ", ", $format) $(, $arg)*); + } + ); +} + +/// A `debug_assert_neq!()` analogue that prints the error with line number information instead of +/// panicking. +macro_rules! nih_debug_assert_neq { + ($left:expr, $right:expr) => ( + if cfg!(debug_assertions) && $left == $right { + nih_log!(concat!("Debug assertion failed: ", stringify!($left), " == ", stringify!($right))); + } + ); + (left:expr, $right:expr, $format:expr $(, $arg:tt)*) => ( + if cfg!(debug_assertions) && $left == $right { + nih_log!(concat!("Debug assertion failed: ", stringify!($left), " == ", stringify!($right), ", ", $format) $(, $arg)*); + } + ); +}