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);
127 std::cout << total_passed <<
' '
128 << total_tests <<
' '
129 << percentage <<
'\n';
132 std::cout <<
"╔" <<
Repeat(
"═", 62) <<
"╗\n";
133 std::cout <<
"║ TEST SUMMARY "
135 std::cout <<
"╠" <<
Repeat(
"═", 62) <<
"╣\n";
137 std::cout <<
"║ Total: " << total_tests
139 48 - std::to_string(total_tests).length(),
' ')
142 std::cout <<
"║ \033[32mPassed: " << total_passed <<
"\033[0m"
144 47 - std::to_string(total_passed).length(),
' ')
147 std::cout <<
"║ \033[31mFailed: " << total_failed <<
"\033[0m"
149 47 - std::to_string(total_failed).length(),
' ')
153 (percentage == 100.0)
155 : (percentage >= 80.0 ?
"\033[33m" :
"\033[31m");
157 std::cout <<
"║ " << color <<
"Success: " << percent_str
159 << std::string(46 - percent_str.length(),
' ')
162 std::cout <<
"╚" <<
Repeat(
"═", 62) <<
"╝\n";
198 std::cout <<
"╔" <<
Repeat(
"═", 62) <<
"╗\n";
199 std::cout <<
"║ \033[1m" <<
m_Name <<
"\033[0m"
200 << std::string(60 -
m_Name.length(),
' ') <<
"║\n";
201 std::cout <<
"╠" <<
Repeat(
"═", 62) <<
"╣\n";
204 std::cout <<
"║ \033[32m[PASS]\033[0m " <<
m_Passed <<
"/"
208 std::to_string(
m_Total).length(),
212 std::cout <<
"║ \033[32m[PASS]\033[0m " <<
m_Passed <<
"/"
216 std::to_string(
m_Total).length(),
220 std::cout <<
"║ \033[31m[FAIL]\033[0m " <<
m_Failed
223 47 - std::to_string(
m_Failed).length(),
' ')
227 std::cout <<
"╚" <<
Repeat(
"═", 62) <<
"╝\n";
233 void Check(
bool cond,
const char* condStr,
const char* msg =
"") {
239 m_Results.push_back({condStr, msg ? msg :
"",
false});
257#define TEST_SCOPE(name) FuncDoodle::TestScope _test_scope(name)
263#define CHECK(cond, msg) _test_scope.Check(cond, #cond, msg)
268#define CHECK_EQ(a, b, msg) _test_scope.Check((a) == (b), #a " == " #b, msg)
273#define CHECK_NE(a, b, msg) _test_scope.Check((a) != (b), #a " != " #b, msg)
278#define CHECK_LT(a, b, msg) _test_scope.Check((a) < (b), #a " < " #b, msg)
284#define CHECK_LE(a, b, msg) _test_scope.Check((a) <= (b), #a " <= " #b, msg)
289#define CHECK_GT(a, b, msg) _test_scope.Check((a) > (b), #a " > " #b, msg)
295#define CHECK_GE(a, b, msg) _test_scope.Check((a) >= (b), #a " >= " #b, msg)
300#define CHECK_NULL(ptr, msg) \
301 _test_scope.Check((ptr) == nullptr, #ptr " == nullptr", msg)
306#define CHECK_NOT_NULL(ptr, msg) \
307 _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:171
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:246
int m_Passed
Definition Test.h:245
int m_Failed
Definition Test.h:245
~TestScope()
Finalizes and prints test scope results.
Definition Test.h:193
std::string m_Name
Definition Test.h:244
void Check(bool cond, const char *condStr, const char *msg="")
Evaluates a test condition.
Definition Test.h:233
TestScope(const char *name)
Creates a named test scope.
Definition Test.h:188
int m_Total
Definition Test.h:245
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:168
const char * name
Definition Test.h:167
int failed
Definition Test.h:168
int passed
Definition Test.h:168
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