| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- export module Core.Test;
- import Core.Logger;
- import Core.TerminalConstants;
- import Core.ToString;
- import Core.Std;
- #define SOURCE const std::source_location& l = std::source_location::current()
- export namespace Core {
- void finalizeTests(void);
- bool addTestResult(const char* file, bool comparison);
- template<typename A, typename B>
- bool test(const A& wanted, const B& actual, SOURCE) {
- const char* file = getShortFileName(l.file_name());
- if(addTestResult(file, static_cast<const B&>(wanted) == actual)) {
- return true;
- }
- print(
- "{}{}:{} - expected '{}' got '{}'{}\n", Terminal::FG_RED, file,
- l.line(), wanted, actual, Terminal::RESET);
- return false;
- }
- template<typename T>
- bool testTrue(const T& actual, SOURCE) {
- return test<T>(true, actual, l);
- }
- template<typename T>
- bool testFalse(const T& actual, SOURCE) {
- return test<T>(false, actual, l);
- }
- bool testString(const char* wanted, const char* actual, SOURCE);
- template<typename A, typename B>
- bool testString(const A& wanted, const B& actual, SOURCE) {
- char wantedString[512];
- size_t lw = toString(wanted, wantedString, sizeof(wantedString));
- char actualString[512];
- size_t la = toString(actual, actualString, sizeof(actualString));
- test(lw, la, l);
- return testString(
- static_cast<const char*>(wantedString),
- static_cast<const char*>(actualString), l);
- }
- bool testFloat(float wanted, float actual, float error, SOURCE);
- bool testNull(const void* p, SOURCE);
- bool testNotNull(const void* p, SOURCE);
- }
|