Initial commit
This commit is contained in:
42
lib/testlib.cpp
Normal file
42
lib/testlib.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
/** @file testlib.cpp
|
||||
*
|
||||
* @author Cory Alexander Balaton (coryab)
|
||||
* @author Janita Ovidie Sandtrøen Willumsen (janitaws)
|
||||
*
|
||||
* @version 1.0
|
||||
*
|
||||
* @brief Implementation of the testing library
|
||||
*
|
||||
* @bug No known bugs
|
||||
* */
|
||||
#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
|
||||
Reference in New Issue
Block a user