2017-12-26 14:11:09 +08:00
|
|
|
#ifndef EXAMPLES_ASSERT_HPP
|
|
|
|
#define EXAMPLES_ASSERT_HPP
|
2017-12-26 12:27:22 +08:00
|
|
|
|
|
|
|
#ifndef NDEBUG
|
2017-12-26 14:11:09 +08:00
|
|
|
#include <exception>
|
|
|
|
#include <iostream>
|
2018-02-08 13:40:34 +08:00
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
#ifdef SOL2_CI
|
|
|
|
struct pre_main {
|
|
|
|
pre_main() {
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
_set_abort_behavior(0, _WRITE_ABORT_MSG);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
} pm;
|
|
|
|
#endif // Prevent lockup when doing Continuous Integration
|
2017-12-26 14:11:09 +08:00
|
|
|
|
2017-12-26 12:27:22 +08:00
|
|
|
# define m_assert(condition, message) \
|
|
|
|
do { \
|
|
|
|
if (! (condition)) { \
|
|
|
|
std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \
|
|
|
|
<< " line " << __LINE__ << ": " << message << std::endl; \
|
|
|
|
std::terminate(); \
|
|
|
|
} \
|
|
|
|
} while (false)
|
|
|
|
|
|
|
|
# define c_assert(condition) \
|
|
|
|
do { \
|
|
|
|
if (! (condition)) { \
|
|
|
|
std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \
|
|
|
|
<< " line " << __LINE__ << std::endl; \
|
|
|
|
std::terminate(); \
|
|
|
|
} \
|
|
|
|
} while (false)
|
|
|
|
#else
|
2017-12-27 20:42:37 +08:00
|
|
|
# define m_assert(condition, message) do { if (false) { (void)(condition); (void)sizeof(message); } } while (false)
|
2017-12-29 01:11:12 +08:00
|
|
|
# define c_assert(condition) do { if (false) { (void)(condition); } } while (false)
|
2017-12-26 12:27:22 +08:00
|
|
|
#endif
|
|
|
|
|
2017-12-26 14:11:09 +08:00
|
|
|
#endif // EXAMPLES_ASSERT_HPP
|