21#ifdef FUNCDOODLE_BUILD_IMTESTS
22#include "imgui_te_engine.h"
23#include "imgui_te_ui.h"
32#ifdef FUNCDOODLE_BUILD_TESTS
33int FuncDoodle_RunTests();
38#define CURRENT_FUNC __FUNCTION__
42#define CURRENT_FUNC __func__
45#ifdef FUNCDOODLE_BUILD_IMTESTS
46int FuncDoodle_RegisterImTests();
47extern ImGuiTestEngine* s_TestEngine;
59 inline std::string
Repeat(std::string_view s,
size_t n) {
61 out.reserve(s.size() * n);
101 const char* name,
int passed,
int total,
int failed) {
102 m_Results.push_back({name, passed, total, failed});
112 int total_passed = 0;
113 int total_failed = 0;
116 total_tests += r.total;
117 total_passed += r.passed;
118 total_failed += r.failed;
121 double percentage = total_tests > 0
122 ? (double)total_passed / total_tests * 100.0
125 std::string percent_str = std::to_string(percentage);
126 percent_str = percent_str.substr(0, percent_str.find(
'.') + 2);
129 std::cout <<
"╔" <<
Repeat(
"═", 62) <<
"╗\n";
130 std::cout <<
"║ TEST SUMMARY "
132 std::cout <<
"╠" <<
Repeat(
"═", 62) <<
"╣\n";
134 std::cout <<
"║ Total: " << total_tests
136 48 - std::to_string(total_tests).length(),
' ')
139 std::cout <<
"║ \033[32mPassed: " << total_passed <<
"\033[0m"
141 47 - std::to_string(total_passed).length(),
' ')
144 std::cout <<
"║ \033[31mFailed: " << total_failed <<
"\033[0m"
146 47 - std::to_string(total_failed).length(),
' ')
150 (percentage == 100.0)
152 : (percentage >= 80.0 ?
"\033[33m" :
"\033[31m");
154 std::cout <<
"║ " << color <<
"Success: " << percent_str
156 << std::string(46 - percent_str.length(),
' ')
159 std::cout <<
"╚" <<
Repeat(
"═", 62) <<
"╝\n";
195 std::cout <<
"╔" <<
Repeat(
"═", 62) <<
"╗\n";
196 std::cout <<
"║ \033[1m" <<
m_Name <<
"\033[0m"
197 << std::string(60 -
m_Name.length(),
' ') <<
"║\n";
198 std::cout <<
"╠" <<
Repeat(
"═", 62) <<
"╣\n";
201 std::cout <<
"║ \033[32m[PASS]\033[0m " <<
m_Passed <<
"/"
205 std::to_string(
m_Total).length(),
209 std::cout <<
"║ \033[32m[PASS]\033[0m " <<
m_Passed <<
"/"
213 std::to_string(
m_Total).length(),
217 std::cout <<
"║ \033[31m[FAIL]\033[0m " <<
m_Failed
220 47 - std::to_string(
m_Failed).length(),
' ')
224 std::cout <<
"╚" <<
Repeat(
"═", 62) <<
"╝\n";
230 void Check(
bool cond,
const char* condStr,
const char* msg =
"") {
236 m_Results.push_back({condStr, msg ? msg :
"",
false});
254#define TEST_SCOPE(name) FuncDoodle::TestScope _test_scope(name)
260#define CHECK(cond, msg) _test_scope.Check(cond, #cond, msg)
265#define CHECK_EQ(a, b, msg) _test_scope.Check((a) == (b), #a " == " #b, msg)
270#define CHECK_NE(a, b, msg) _test_scope.Check((a) != (b), #a " != " #b, msg)
275#define CHECK_LT(a, b, msg) _test_scope.Check((a) < (b), #a " < " #b, msg)
281#define CHECK_LE(a, b, msg) _test_scope.Check((a) <= (b), #a " <= " #b, msg)
286#define CHECK_GT(a, b, msg) _test_scope.Check((a) > (b), #a " > " #b, msg)
292#define CHECK_GE(a, b, msg) _test_scope.Check((a) >= (b), #a " >= " #b, msg)
297#define CHECK_NULL(ptr, msg) \
298 _test_scope.Check((ptr) == nullptr, #ptr " == nullptr", msg)
303#define CHECK_NOT_NULL(ptr, msg) \
304 _test_scope.Check((ptr) != nullptr, #ptr " != nullptr", msg)
Global singleton collecting test scope results.
Definition Test.h:84
static TestRegistry & Instance()
Returns the global test registry singleton.
Definition Test.h:92
std::vector< ScopeResult > m_Results
Definition Test.h:168
void RegisterScope(const char *name, int passed, int total, int failed)
Registers a completed test scope.
Definition Test.h:100
void PrintSummary()
Prints a full summary of all executed tests.
Definition Test.h:110
std::vector< TestResult > m_Results
Definition Test.h:243
int m_Passed
Definition Test.h:242
int m_Failed
Definition Test.h:242
~TestScope()
Finalizes and prints test scope results.
Definition Test.h:190
std::string m_Name
Definition Test.h:241
void Check(bool cond, const char *condStr, const char *msg="")
Evaluates a test condition.
Definition Test.h:230
TestScope(const char *name)
Creates a named test scope.
Definition Test.h:185
int m_Total
Definition Test.h:242
The FuncDoodle C++ namespace.
Definition Common.h:12
std::string Repeat(std::string_view s, size_t n)
Repeats a string N times.
Definition Test.h:59
int total
Definition Test.h:165
const char * name
Definition Test.h:164
int failed
Definition Test.h:165
int passed
Definition Test.h:165
Represents a single failed or recorded test assertion.
Definition Test.h:71
std::string message
Optional failure message.
Definition Test.h:73
bool passed
Whether the test passed.
Definition Test.h:74
std::string condition
Stringified test condition.
Definition Test.h:72