8 #ifndef Sawyer_Assert_H
9 #define Sawyer_Assert_H
11 #include <Sawyer/Sawyer.h>
95 #if __cplusplus >= 201103L
98 void fail(
const char *mesg,
const char *expr,
const std::string ¬e,
99 const char *filename,
unsigned linenum,
const char *funcname);
103 const char *filename,
unsigned linenum,
const char *funcname);
118 #define ASSERT_always_require(expr) ASSERT_always_require2(expr, "")
119 #define ASSERT_always_require2(expr, note) \
121 static_cast<void>(0) : \
122 Sawyer::Assert::fail("assertion failed", "required: " #expr, (note), \
123 __FILE__, __LINE__, SAWYER_PRETTY_FUNCTION))
125 #define ASSERT_always_forbid(expr) ASSERT_always_forbid2(expr, "")
126 #define ASSERT_always_forbid2(expr, note) \
128 static_cast<void>(0) : \
129 Sawyer::Assert::fail("assertion failed", \
130 "forbidden: " #expr, (note), __FILE__, __LINE__, SAWYER_PRETTY_FUNCTION))
132 #define ASSERT_always_not_null(expr) ASSERT_always_not_null2(expr, "")
133 #define ASSERT_always_not_null2(expr, note) \
135 static_cast<void>(0) : \
136 Sawyer::Assert::fail("null pointer", \
137 #expr, (note), __FILE__, __LINE__, SAWYER_PRETTY_FUNCTION))
139 #define ASSERT_always_not_reachable(note) \
140 Sawyer::Assert::fail("reached impossible state", NULL, (note), \
141 __FILE__, __LINE__, SAWYER_PRETTY_FUNCTION);
143 #define ASSERT_always_not_implemented(note) \
144 Sawyer::Assert::fail("not implemented yet", NULL, (note), \
145 __FILE__, __LINE__, SAWYER_PRETTY_FUNCTION)
147 #define ASSERT_always_this()
155 #define ASSERT_require(expr)
156 #define ASSERT_require2(expr, note)
157 #define ASSERT_forbid(expr)
158 #define ASSERT_forbid2(expr, note)
159 #define ASSERT_not_null(expr)
160 #define ASSERT_not_null2(expr, note)
161 #define ASSERT_not_reachable(note) ASSERT_always_not_reachable(note)
162 #define ASSERT_not_implemented(note) ASSERT_always_not_implemented(note)
163 #define ASSERT_this()
167 #define ASSERT_require(expr) ASSERT_always_require(expr)
168 #define ASSERT_require2(expr, note) ASSERT_always_require2(expr, note)
169 #define ASSERT_forbid(expr) ASSERT_always_forbid(expr)
170 #define ASSERT_forbid2(expr, note) ASSERT_always_forbid2(expr, note)
171 #define ASSERT_not_null(expr) ASSERT_always_not_null(expr)
172 #define ASSERT_not_null2(expr, note) ASSERT_always_not_null2(expr, note)
173 #define ASSERT_not_reachable(note) ASSERT_always_not_reachable(note)
174 #define ASSERT_not_implemented(note) ASSERT_always_not_implemented(note)
175 #define ASSERT_this()
184 Sawyer::Assert::fail("not implemented yet", NULL, (note), \
185 __FILE__, __LINE__, SAWYER_PRETTY_FUNCTION)
187 #define FIXME(note) \
188 Sawyer::Assert::fail("needs to be fixed", NULL, (note), \
189 __FILE__, __LINE__, SAWYER_PRETTY_FUNCTION)
void(* AssertFailureHandler)(const char *mesg, const char *expr, const std::string ¬e, const char *filename, unsigned linenum, const char *funcname)
Type for user-defined assertion failure handler.
Name space for the entire library.
AssertFailureHandler assertFailureHandler
Optional user callback to handle assertion failures.
void fail(const char *mesg, const char *expr, const std::string ¬e, const char *filename, unsigned linenum, const char *funcname)
Cause immediate failure.