2011-09-09 21:24:18 +02:00
|
|
|
#ifndef assert_hh_INCLUDED
|
|
|
|
#define assert_hh_INCLUDED
|
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2016-02-29 23:15:36 +01:00
|
|
|
class StringView;
|
2015-05-29 14:35:09 +02:00
|
|
|
|
|
|
|
// return true if user asked to ignore the error
|
2016-02-29 23:15:36 +01:00
|
|
|
bool notify_fatal_error(StringView message);
|
2015-05-29 14:35:09 +02:00
|
|
|
|
2012-10-17 17:01:08 +02:00
|
|
|
void on_assert_failed(const char* message);
|
2012-10-16 16:16:32 +02:00
|
|
|
|
2011-09-09 21:24:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#define STRINGIFY(X) #X
|
|
|
|
#define TOSTRING(X) STRINGIFY(X)
|
|
|
|
|
2013-02-27 19:02:01 +01:00
|
|
|
#ifdef KAK_DEBUG
|
2017-02-19 15:37:32 +01:00
|
|
|
#define kak_assert(...) do { \
|
2016-05-17 20:39:55 +02:00
|
|
|
if (not (__VA_ARGS__)) \
|
|
|
|
on_assert_failed("assert failed \"" #__VA_ARGS__ \
|
2017-02-19 15:37:32 +01:00
|
|
|
"\" at " __FILE__ ":" TOSTRING(__LINE__)); \
|
2017-02-23 00:00:54 +01:00
|
|
|
} while (false)
|
2018-03-15 13:02:27 +01:00
|
|
|
|
|
|
|
#define kak_expect_throw(exception_type, ...) try {\
|
|
|
|
__VA_ARGS__; \
|
|
|
|
on_assert_failed("expression \"" #__VA_ARGS__ \
|
|
|
|
"\" did not throw \"" #exception_type \
|
|
|
|
"\" at " __FILE__ ":" TOSTRING(__LINE__)); \
|
|
|
|
} catch (exception_type &err) {}
|
2013-02-27 19:02:01 +01:00
|
|
|
#else
|
2017-10-19 22:20:44 +02:00
|
|
|
#define kak_assert(...) do { (void)sizeof(__VA_ARGS__); } while(false)
|
2018-03-15 13:02:27 +01:00
|
|
|
#define kak_expect_throw(_, ...) do { (void)sizeof(__VA_ARGS__); } while(false)
|
2013-02-27 19:02:01 +01:00
|
|
|
#endif
|
|
|
|
|
2011-09-09 21:24:18 +02:00
|
|
|
|
|
|
|
#endif // assert_hh_INCLUDED
|