| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- export module Core.Test;
- import Core.Logger;
- import Core.TerminalConstants;
- import Core.ToString;
- import Core.Types;
- import Core.Std;
- #define SOURCE const std::source_location& l = std::source_location::current()
- export namespace Core {
- void finalizeTests(void) noexcept;
- bool addTestResult(const char* file, bool comparison) noexcept;
- template<typename A, typename B>
- bool test(const A& wanted, const B& actual, SOURCE) noexcept {
- 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) noexcept {
- return test<T>(true, actual, l);
- }
- template<typename T>
- bool testFalse(const T& actual, SOURCE) noexcept {
- return test<T>(false, actual, l);
- }
- bool testString(const char* wanted, const char* actual, SOURCE) noexcept;
- template<typename A, typename B>
- bool testString(const A& wanted, const B& actual, SOURCE) noexcept {
- String<512> wantedString;
- size_t lw = wantedString.add(wanted);
- String<512> actualString;
- size_t la = actualString.add(actual);
- 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) noexcept;
- bool testNull(const void* p, SOURCE) noexcept;
- bool testNotNull(const void* p, SOURCE) noexcept;
- }
|