Loading...
Searching...
No Matches
testlib.cpp
Go to the documentation of this file.
#include "testlib.hpp"
namespace details {
void m_assert(bool expr, std::string expr_str, std::string f, std::string file,
int line, std::string msg)
{
std::function<void(const std::string &)> print_message =
[](const std::string &msg) {
if (msg.size() > 0) {
std::cout << "message: " << msg << "\n\n";
}
else {
std::cout << "\n";
}
};
std::string new_assert(f.size() + (expr ? 4 : 6), '-');
std::cout << "\x1B[36m" << new_assert << "\033[0m\n";
std::cout << f << ": ";
if (expr) {
std::cout << "\x1B[32mOK\033[0m\n";
print_message(msg);
}
else {
std::cout << "\x1B[31mFAIL\033[0m\n";
print_message(msg);
std::cout << file << " " << line << ": Assertion \"" << expr_str
<< "\" Failed\n\n";
abort();
}
}
} // namespace details
testlib.hpp
A small test library.
details::m_assert
void m_assert(bool expr, std::string expr_str, std::string func, std::string file, int line, std::string msg)
Test an expression, confirm that test is ok, or abort execution.
Definition: testlib.cpp:15