From 91bf5ecec095e881fdcc358ca26027c04f08b381 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sat, 11 Jan 2025 17:33:06 +0100 Subject: [PATCH] Some better assertion macros --- common/iassert.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/common/iassert.h b/common/iassert.h index 841a806..3e60e05 100644 --- a/common/iassert.h +++ b/common/iassert.h @@ -8,3 +8,24 @@ assert(cond); \ } \ } while (0) + +#define ASSERT_EQ(expected, actual) \ + do { \ + if ((expected) != (actual)) { \ + std::cerr << "Assertion failed: (" #expected " == " #actual ") " \ + << "Expected: " << (expected) \ + << ", Actual: " << (actual) << "\n"; \ + assert((expected) == (actual)); \ + } \ + } while (0) + +#define ASSERT_EQMSG(expected, actual, msg) \ + do { \ + if ((expected) != (actual)) { \ + std::cerr << "Assertion failed: " << msg << "\n" \ + << "(" #expected " == " #actual ") " \ + << "Expected: " << (expected) \ + << ", Actual: " << (actual) << "\n"; \ + assert((expected) == (actual)); \ + } \ + } while (0)