Skip to content

Commit 014a948

Browse files
committed
TestEngine: *BREAKING* reworked ImGuiTestEngine_GetResult() as ImGuiTestEngine_GetResultSummary().
1 parent e9851ac commit 014a948

File tree

5 files changed

+45
-16
lines changed

5 files changed

+45
-16
lines changed

docs/CHANGELOG.txt

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ CHANGELOG
66
** For a while this is going to ONLY INCLUDE BREAKING CHANGES.
77

88
2025/03/17:
9+
- TestEngine: *BREAKING* reworked ImGuiTestEngine_GetResult() as ImGuiTestEngine_GetResultSummary()
10+
outputting a structure where we can add more fields.
11+
Prev: void ImGuiTestEngine_GetResult(ImGuiTestEngine* engine, int& count_tested, int& count_passed);
12+
Now: void ImGuiTestEngine_GetResultSummary(ImGuiTestEngine* engine, ImGuiTestEngineResultSummary* out_result);
13+
New structure include the number of tests remaining in queue (for when aborting or crashing).
914
- TestEngine: helper crash handler installed by ImGuiTestEngine_InstallDefaultCrashHandler()
1015
always print a crash string and extra info, even if result export settings are set to None.
1116

imgui_test_engine/imgui_te_engine.cpp

+14-4
Original file line numberDiff line numberDiff line change
@@ -1458,20 +1458,30 @@ void ImGuiTestEngine_UpdateTestsSourceLines(ImGuiTestEngine* engine)
14581458
}
14591459
}
14601460

1461-
void ImGuiTestEngine_GetResult(ImGuiTestEngine* engine, int& count_tested, int& count_success)
1461+
// count_remaining could be >0 if e.g. called during a crash handler or aborting a run.
1462+
void ImGuiTestEngine_GetResultSummary(ImGuiTestEngine* engine, ImGuiTestEngineResultSummary* out_results)
14621463
{
1463-
count_tested = 0;
1464-
count_success = 0;
1464+
int count_tested = 0;
1465+
int count_success = 0;
1466+
int count_remaining = 0;
14651467
for (int n = 0; n < engine->TestsAll.Size; n++)
14661468
{
14671469
ImGuiTest* test = engine->TestsAll[n];
1468-
if (test->Output.Status == ImGuiTestStatus_Unknown || test->Output.Status == ImGuiTestStatus_Queued)
1470+
if (test->Output.Status == ImGuiTestStatus_Unknown)
14691471
continue;
1472+
if (test->Output.Status == ImGuiTestStatus_Queued)
1473+
{
1474+
count_remaining++;
1475+
continue;
1476+
}
14701477
IM_ASSERT(test->Output.Status != ImGuiTestStatus_Running);
14711478
count_tested++;
14721479
if (test->Output.Status == ImGuiTestStatus_Success)
14731480
count_success++;
14741481
}
1482+
out_results->CountTested = count_tested;
1483+
out_results->CountSuccess = count_success;
1484+
out_results->CountInQueue = count_remaining;
14751485
}
14761486

14771487
// Get a copy of the test list

imgui_test_engine/imgui_te_engine.h

+14-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ struct ImGuiTestContext; // Context while a test is running
4343
struct ImGuiTestCoroutineInterface; // Interface to expose coroutine functions (imgui_te_coroutine provides a default implementation for C++11 using std::thread, but you may use your own)
4444
struct ImGuiTestEngine; // Test engine instance
4545
struct ImGuiTestEngineIO; // Test engine public I/O
46+
struct ImGuiTestEngineResultSummary;// Output of ImGuiTestEngine_GetResultSummary()
4647
struct ImGuiTestItemInfo; // Info queried from item (id, geometry, status flags, debug label)
4748
struct ImGuiTestItemList; // A list of items
4849
struct ImGuiTestInputs; // Simulated user inputs (will be fed into ImGuiIO by the test engine)
@@ -153,6 +154,13 @@ enum ImGuiTestRunFlags_
153154
// TODO: Add GuiFunc options
154155
};
155156

157+
struct ImGuiTestEngineResultSummary
158+
{
159+
int CountTested = 0; // Number of tests executed
160+
int CountSuccess = 0; // Number of tests succeeded
161+
int CountInQueue = 0; // Number of tests remaining in queue (e.g. aborted, crashed)
162+
};
163+
156164
//-------------------------------------------------------------------------
157165
// Functions
158166
//-------------------------------------------------------------------------
@@ -206,10 +214,15 @@ IMGUI_API ImGuiTest* ImGuiTestEngine_FindTestByName(ImGuiTestEngine* en
206214
// FIXME: Clarify API to avoid function calls vs raw bools in ImGuiTestEngineIO
207215
IMGUI_API bool ImGuiTestEngine_IsTestQueueEmpty(ImGuiTestEngine* engine);
208216
IMGUI_API bool ImGuiTestEngine_IsUsingSimulatedInputs(ImGuiTestEngine* engine);
209-
IMGUI_API void ImGuiTestEngine_GetResult(ImGuiTestEngine* engine, int& count_tested, int& success_count);
217+
IMGUI_API void ImGuiTestEngine_GetResultSummary(ImGuiTestEngine* engine, ImGuiTestEngineResultSummary* out_results);
210218
IMGUI_API void ImGuiTestEngine_GetTestList(ImGuiTestEngine* engine, ImVector<ImGuiTest*>* out_tests);
211219
IMGUI_API void ImGuiTestEngine_GetTestQueue(ImGuiTestEngine* engine, ImVector<ImGuiTestRunTask>* out_tests);
212220

221+
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
222+
// Obsoleted 2025/03/17
223+
static inline void ImGuiTestEngine_GetResult(ImGuiTestEngine* engine, int& out_count_tested, int& out_count_passed) { ImGuiTestEngineResultSummary summary; ImGuiTestEngine_GetResultSummary(engine, &summary); out_count_tested = summary.CountTested; out_count_passed = summary.CountPassed; }
224+
#endif
225+
213226
// Functions: Crash Handling
214227
// Ensure past test results are properly exported even if application crash during a test.
215228
IMGUI_API void ImGuiTestEngine_InstallDefaultCrashHandler(); // Install default crash handler (if you don't have one)

imgui_test_engine/imgui_te_exporters.cpp

+9-7
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,23 @@ static void ImGuiTestEngine_ExportJUnitXml(ImGuiTestEngine* engine, const char*
3030

3131
void ImGuiTestEngine_PrintResultSummary(ImGuiTestEngine* engine)
3232
{
33-
int count_tested = 0;
34-
int count_success = 0;
35-
ImGuiTestEngine_GetResult(engine, count_tested, count_success);
33+
ImGuiTestEngineResultSummary summary;
34+
ImGuiTestEngine_GetResultSummary(engine, &summary);
3635

37-
if (count_success < count_tested)
36+
if (summary.CountSuccess < summary.CountTested)
3837
{
3938
printf("\nFailing tests:\n");
4039
for (ImGuiTest* test : engine->TestsAll)
4140
if (test->Output.Status == ImGuiTestStatus_Error)
4241
printf("- %s\n", test->Name);
4342
}
4443

45-
ImOsConsoleSetTextColor(ImOsConsoleStream_StandardOutput, (count_success == count_tested) ? ImOsConsoleTextColor_BrightGreen : ImOsConsoleTextColor_BrightRed);
46-
printf("\nTests Result: %s\n", (count_success == count_tested) ? "OK" : "Errors");
47-
printf("(%d/%d tests passed)\n", count_success, count_tested);
44+
bool success = (summary.CountSuccess == summary.CountTested);
45+
ImOsConsoleSetTextColor(ImOsConsoleStream_StandardOutput, success ? ImOsConsoleTextColor_BrightGreen : ImOsConsoleTextColor_BrightRed);
46+
printf("\nTests Result: %s\n", success ? "OK" : "Errors");
47+
printf("(%d/%d tests passed)\n", summary.CountSuccess, summary.CountTested);
48+
if (summary.CountInQueue > 0)
49+
printf("(%d queued tests remaining)\n", summary.CountInQueue);
4850
ImOsConsoleSetTextColor(ImOsConsoleStream_StandardOutput, ImOsConsoleTextColor_White);
4951
}
5052

imgui_test_suite/imgui_test_suite.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -629,11 +629,10 @@ int main(int argc, char** argv)
629629
ImGuiTestAppErrorCode error_code = ImGuiTestAppErrorCode_Success;
630630
if (!aborted)
631631
{
632-
int count_tested = 0;
633-
int count_success = 0;
634-
ImGuiTestEngine_GetResult(engine, count_tested, count_success);
632+
ImGuiTestEngineResultSummary summary;
633+
ImGuiTestEngine_GetResultSummary(engine, &summary);
635634
ImGuiTestEngine_PrintResultSummary(engine);
636-
if (count_tested != count_success)
635+
if (summary.CountSuccess < summary.CountTested)
637636
error_code = ImGuiTestAppErrorCode_TestFailed;
638637
}
639638

0 commit comments

Comments
 (0)