17 #ifndef COM_BORA_SOFTWARE__BALAU_DEV__ASSERT 18 #define COM_BORA_SOFTWARE__BALAU_DEV__ASSERT 20 #include <boost/core/ignore_unused.hpp> 23 #ifdef BALAU_ENABLE_STACKTRACES 24 #include <boost/stacktrace.hpp> 39 public:
static void fail(
const char * fatalMessage) {
40 performAssertion(
false, fatalMessage,
"Fail called");
48 public:
template <
typename StringFunctionT>
49 static void assertion(
bool test, StringFunctionT
function) {
50 performAssertion(test,
function,
"Bug found");
56 public:
static void assertion(
bool test,
const char * fatalMessage) {
57 performAssertion(test, fatalMessage,
"Bug found");
64 performAssertion(test,
"",
"Bug found");
70 public:
template <
typename TestFunctionT,
typename StringFunctionT>
71 static void assertion(TestFunctionT test, StringFunctionT
function) {
72 performAssertion(test,
function,
"Bug found");
78 public:
template <
typename TestFunctionT>
79 static void assertion(TestFunctionT test,
const char * fatalMessage) {
80 performAssertion(test, fatalMessage,
"Bug found");
86 public:
template <
typename TestFunctionT>
88 performAssertion(test,
"",
"Bug found");
93 private:
template <
typename FunctionT>
94 static void performAssertion(
bool test, FunctionT
function,
const char * testType) {
95 boost::ignore_unused(test);
96 boost::ignore_unused(
function);
97 boost::ignore_unused(testType);
101 const std::string message =
function();
102 abortProcess(message.c_str(), testType);
107 private:
template <
typename TestT,
typename FunctionT>
108 static void performAssertion(TestT test, FunctionT
function,
const char * testType) {
109 boost::ignore_unused(test);
110 boost::ignore_unused(
function);
111 boost::ignore_unused(testType);
115 const std::string message =
function();
116 abortProcess(message.c_str(), testType);
121 private:
static void performAssertion(
bool test,
const char * fatalMessage,
const char * testType) {
122 boost::ignore_unused(test);
123 boost::ignore_unused(fatalMessage);
124 boost::ignore_unused(testType);
128 abortProcess(fatalMessage, testType);
133 private:
template <
typename TestT>
134 static void performAssertion(TestT test,
const char * fatalMessage,
const char * testType) {
135 boost::ignore_unused(test);
136 boost::ignore_unused(fatalMessage);
137 boost::ignore_unused(testType);
141 abortProcess(fatalMessage, testType);
146 private:
static void abortProcess(
const char * fatalMessage,
const char * testType) {
147 std::ostringstream str;
149 if (fatalMessage !=
nullptr) {
150 str << testType <<
": " << fatalMessage <<
"\n";
152 str << testType <<
"\n";
155 #ifdef BALAU_ENABLE_STACKTRACES 156 str <<
"Stack trace: " << boost::stacktrace::stacktrace() <<
"\n";
159 str <<
"Program will abort now\n";
160 std::cerr << str.str();
167 #endif // COM_BORA_SOFTWARE__BALAU_DEV__ASSERT static void assertion(TestFunctionT test, StringFunctionT function)
If the bug test assertion predicate function fails, abort after logging the message supplied by the f...
Definition: Assert.hpp:71
The root Balau namespace.
Definition: ApplicationConfiguration.hpp:23
static void fail(const char *fatalMessage)
Abort after logging the message.
Definition: Assert.hpp:39
static void assertion(TestFunctionT test, const char *fatalMessage)
If the bug test assertion predicate function fails, abort after logging the message.
Definition: Assert.hpp:79
static void assertion(bool test, const char *fatalMessage)
If the bug test assertion fails, abort after logging the message.
Definition: Assert.hpp:56
static void assertion(bool test)
Abort if the bug test fails.
Definition: Assert.hpp:63
static void assertion(TestFunctionT test)
Abort if the bug test assertion predicate function fails.
Definition: Assert.hpp:87
An assertion class for development purposes.
Definition: Assert.hpp:35
static void assertion(bool test, StringFunctionT function)
If the bug test assertion fails, abort after logging the message supplied by the function.
Definition: Assert.hpp:49