debug: make assertions debug-only

This commit is contained in:
Danny Robson 2015-01-28 15:01:17 +11:00
parent cee9951f82
commit d7db3d8d29

View File

@ -28,8 +28,9 @@
///////////////////////////////////////////////////////////////////////////////
#ifdef ENABLE_DEBUGGING
#define DEBUG_ONLY(X) \
X;
#define DEBUG_ONLY(X) do { \
X \
} while (0)
#else
#define DEBUG_ONLY(X)
#endif
@ -43,14 +44,18 @@
///////////////////////////////////////////////////////////////////////////////
#define TRACE { \
DEBUG_ONLY( \
std::cerr << __FILE__ << ":" << __func__ << ":" << __LINE__ << std::endl; \
); \
}
#define WARN(C) do { \
DEBUG_ONLY( \
if (C) { \
std::cerr << __FILE__ << ":" << __func__ << ":" << __LINE__ << ", " << #C << std::endl; \
} \
); \
} while (0)
@ -77,6 +82,7 @@
///////////////////////////////////////////////////////////////////////////////
#define CHECK_EQ(A,B) do { \
DEBUG_ONLY( \
const auto __a = (A); \
const auto __b = (B); \
_CHECK_META (almost_equal (__a, __b), \
@ -91,11 +97,13 @@
<< "__b: " << #B << " is " << __b << ")"; \
panic (__debug_os.str ()); \
}); \
); \
} while (0)
///////////////////////////////////////////////////////////////////////////////
#define CHECK_LT(A,B) do { \
DEBUG_ONLY( \
const auto __a = (A); \
const auto __b = (B); \
_CHECK_META (__a < __b, \
@ -109,11 +117,13 @@
<< "__b: " << #B << " is " << __b << ")"; \
panic (__debug_check_lt_os.str ()); \
}); \
); \
} while (0)
///////////////////////////////////////////////////////////////////////////////
#define CHECK_LE(A,B) do { \
DEBUG_ONLY( \
const auto __a = (A); \
const auto __b = (B); \
_CHECK_META (__a <= __b, \
@ -127,11 +137,13 @@
<< "__b: " << #B << " is " << __b << ")"; \
panic (__debug_check_lt_os.str ()); \
}); \
); \
} while (0)
///////////////////////////////////////////////////////////////////////////////
#define CHECK_GT(A,B) do { \
DEBUG_ONLY( \
const auto __a = (A); \
const auto __b = (B); \
_CHECK_META (__a > __b, \
@ -145,11 +157,13 @@
<< "__b: " << #B << " is " << __b << ")"; \
panic (__debug_check_gt_os.str ()); \
}); \
); \
} while (0)
///////////////////////////////////////////////////////////////////////////////
#define CHECK_GE(A,B) do { \
DEBUG_ONLY( \
const auto __a = (A); \
const auto __b = (B); \
_CHECK_META (__a >= __b, \
@ -163,11 +177,13 @@
<< "__b: " << #B << " is " << __b << ")"; \
panic (__debug_check_gt_os.str ()); \
}); \
); \
} while (0)
///////////////////////////////////////////////////////////////////////////////
#define CHECK_NEQ(A,B) do { \
DEBUG_ONLY( \
const auto __a = (A); \
const auto __b = (B); \
_CHECK_META (!almost_equal (__a, __b), \
@ -180,11 +196,13 @@
<< "__b: " << #B << " is " << __b << ")"; \
panic (__debug_neq_os.str ()); \
}); \
); \
} while (0)
///////////////////////////////////////////////////////////////////////////////
#define CHECK_THROWS(E,C) do { \
DEBUG_ONLY( \
bool caught = false; \
\
try \
@ -194,16 +212,19 @@
\
if (!caught) \
panic ("expected exception: " #E); \
); \
} while (0)
///////////////////////////////////////////////////////////////////////////////
#define CHECK_NOTHROW(C) do { \
DEBUG_ONLY( \
try { \
C; \
} catch (...) { \
panic ("unexpected exception"); \
} \
); \
} while (0)