REXM: REVIEWED: Automated testing for Web

This commit is contained in:
Ray
2025-11-19 09:54:54 +01:00
parent 8081d2bd07
commit 33cee1146c

View File

@ -1491,6 +1491,9 @@ int main(int argc, char *argv[])
LOG("INFO: [%i/%i] Testing example: [%s]\n", i + 1, exBuildListCount, exName); LOG("INFO: [%i/%i] Testing example: [%s]\n", i + 1, exBuildListCount, exName);
// Create directory for logs (build and run logs)
MakeDirectory(TextFormat("%s/%s/logs", exBasePath, exCategory));
// Steps to follow // Steps to follow
// STEP 1: Load example.c and replace required code to inject basic testing code: frames to run // STEP 1: Load example.c and replace required code to inject basic testing code: frames to run
// OPTION 1: Code injection required multiple changes for testing but it does not require raylib changes! // OPTION 1: Code injection required multiple changes for testing but it does not require raylib changes!
@ -1510,7 +1513,7 @@ int main(int argc, char *argv[])
TextFormat("%s/%s/%s.original.c", exBasePath, exCategory, exName)); TextFormat("%s/%s/%s.original.c", exBasePath, exCategory, exName));
char *srcText = LoadFileText(TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName)); char *srcText = LoadFileText(TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName));
//#define BUILD_TESTING_WEB #define BUILD_TESTING_WEB
#if defined(BUILD_TESTING_WEB) #if defined(BUILD_TESTING_WEB)
static const char *mainReplaceText = static const char *mainReplaceText =
"#include <stdio.h>\n" "#include <stdio.h>\n"
@ -1557,13 +1560,14 @@ int main(int argc, char *argv[])
// Build: raylib.com/examples/<category>/<category>_example_name.data // Build: raylib.com/examples/<category>/<category>_example_name.data
// Build: raylib.com/examples/<category>/<category>_example_name.wasm // Build: raylib.com/examples/<category>/<category>_example_name.wasm
// Build: raylib.com/examples/<category>/<category>_example_name.js // Build: raylib.com/examples/<category>/<category>_example_name.js
#if defined(_WIN32) #if defined(_WIN32)
LOG("INFO: [%s] Building example for PLATFORM_WEB (Host: Win32)\n", exName); LOG("INFO: [%s] Building example for PLATFORM_WEB (Host: Win32)\n", exName);
system(TextFormat("mingw32-make -C %s -f Makefile.Web %s/%s PLATFORM=PLATFORM_WEB -B > %s/%s/logs/%s.build.log 2>&1", exBasePath, exCategory, exName)); system(TextFormat("mingw32-make -C %s -f Makefile.Web %s/%s PLATFORM=PLATFORM_WEB -B > %s/%s/logs/%s.build.log 2>&1",
#else exBasePath, exCategory, exName, exBasePath, exCategory, exName));
#else
LOG("INFO: [%s] Building example for PLATFORM_WEB (Host: POSIX)\n", exName); LOG("INFO: [%s] Building example for PLATFORM_WEB (Host: POSIX)\n", exName);
system(TextFormat("make -C %s -f Makefile.Web %s/%s PLATFORM=PLATFORM_WEB -B", exBasePath, exCategory, exName)); system(TextFormat("make -C %s -f Makefile.Web %s/%s PLATFORM=PLATFORM_WEB -B", exBasePath, exCategory, exName));
#endif #endif
// Restore original source code before continue // Restore original source code before continue
FileCopy(TextFormat("%s/%s/%s.original.c", exBasePath, exCategory, exName), FileCopy(TextFormat("%s/%s/%s.original.c", exBasePath, exCategory, exName),
TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName)); TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName));
@ -1571,7 +1575,7 @@ int main(int argc, char *argv[])
// STEP 3: Run example on browser // STEP 3: Run example on browser
ChangeDirectory(TextFormat("%s/%s", exBasePath, exCategory)); ChangeDirectory(TextFormat("%s/%s", exBasePath, exCategory));
system("start python -m http.server 8080"); // TODO: Init localhost just once! if (i == 0) system("start python -m http.server 8080"); // TODO: Init localhost just once!
system(TextFormat("start explorer \"http:\\localhost:8080/%s.html", exName)); system(TextFormat("start explorer \"http:\\localhost:8080/%s.html", exName));
// NOTE: Example .log is automatically downloaded into system Downloads directory on browser-example exectution // NOTE: Example .log is automatically downloaded into system Downloads directory on browser-example exectution
@ -1595,22 +1599,20 @@ int main(int argc, char *argv[])
SaveFileText(TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName), srcTextUpdated[2]); SaveFileText(TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName), srcTextUpdated[2]);
for (int i = 0; i < 3; i++) { MemFree(srcTextUpdated[i]); srcTextUpdated[i] = NULL; } for (int i = 0; i < 3; i++) { MemFree(srcTextUpdated[i]); srcTextUpdated[i] = NULL; }
MakeDirectory(TextFormat("%s/%s/logs", exBasePath, exCategory));
// STEP 2: Build example for DESKTOP platform // STEP 2: Build example for DESKTOP platform
#if defined(_WIN32) #if defined(_WIN32)
// Set required environment variables // Set required environment variables
//putenv(TextFormat("RAYLIB_DIR=%s\\..", exBasePath)); //putenv(TextFormat("RAYLIB_DIR=%s\\..", exBasePath));
_putenv("PATH=%PATH%;C:\\raylib\\w64devkit\\bin"); _putenv("PATH=%PATH%;C:\\raylib\\w64devkit\\bin");
//putenv("MAKE=mingw32-make"); //putenv("MAKE=mingw32-make");
//ChangeDirectory(exBasePath); //ChangeDirectory(exBasePath);
#endif #endif
// Build example for PLATFORM_DESKTOP // Build example for PLATFORM_DESKTOP
#if defined(_WIN32) #if defined(_WIN32)
LOG("INFO: [%s] Building example for PLATFORM_DESKTOP (Host: Win32)\n", exName); LOG("INFO: [%s] Building example for PLATFORM_DESKTOP (Host: Win32)\n", exName);
system(TextFormat("mingw32-make -C %s %s/%s PLATFORM=PLATFORM_DESKTOP -B > %s/%s/logs/%s.build.log 2>&1", system(TextFormat("mingw32-make -C %s %s/%s PLATFORM=PLATFORM_DESKTOP -B > %s/%s/logs/%s.build.log 2>&1",
exBasePath, exCategory, exName, exBasePath, exCategory, exName)); exBasePath, exCategory, exName, exBasePath, exCategory, exName));
#else #else
LOG("INFO: [%s] Building example for PLATFORM_DESKTOP (Host: POSIX)\n", exName); LOG("INFO: [%s] Building example for PLATFORM_DESKTOP (Host: POSIX)\n", exName);
system(TextFormat("make -C %s %s/%s PLATFORM=PLATFORM_DESKTOP -B", exBasePath, exCategory, exName)); system(TextFormat("make -C %s %s/%s PLATFORM=PLATFORM_DESKTOP -B", exBasePath, exCategory, exName));
#endif #endif
@ -1623,7 +1625,7 @@ int main(int argc, char *argv[])
// NOTE: Not easy to retrieve process return value from system(), it's platform dependant // NOTE: Not easy to retrieve process return value from system(), it's platform dependant
ChangeDirectory(TextFormat("%s/%s", exBasePath, exCategory)); ChangeDirectory(TextFormat("%s/%s", exBasePath, exCategory));
system(TextFormat("%s --frames 2 > logs/%s.log", exName, exName)); system(TextFormat("%s --frames 2 > logs/%s.log", exName, exName));
#endif
// STEP 4: Load and validate log info // STEP 4: Load and validate log info
//--------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------
// Load <example_name>.build.log to check for compilation warnings // Load <example_name>.build.log to check for compilation warnings
@ -1640,7 +1642,11 @@ int main(int argc, char *argv[])
UnloadTextLines(exTestBuildLogLines, exTestBuildLogLinesCount); UnloadTextLines(exTestBuildLogLines, exTestBuildLogLinesCount);
UnloadFileText(exTestBuildLog); UnloadFileText(exTestBuildLog);
#if defined(BUILD_TESTING_WEB)
char *exTestLog = LoadFileText(TextFormat("C:/Users/raysa/Downloads/%s.log", exName));
#else
char *exTestLog = LoadFileText(TextFormat("%s/%s/logs/%s.log", exBasePath, exCategory, exName)); char *exTestLog = LoadFileText(TextFormat("%s/%s/logs/%s.log", exBasePath, exCategory, exName));
#endif
int exTestLogLinesCount = 0; int exTestLogLinesCount = 0;
char **exTestLogLines = LoadTextLines(exTestLog, &exTestLogLinesCount); char **exTestLogLines = LoadTextLines(exTestLog, &exTestLogLinesCount);
@ -1670,11 +1676,27 @@ int main(int argc, char *argv[])
UnloadTextLines(exTestLogLines, exTestLogLinesCount); UnloadTextLines(exTestLogLines, exTestLogLinesCount);
UnloadFileText(exTestLog); UnloadFileText(exTestLog);
//--------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------
#endif
} }
// STEP 5: Generate testing report/table with results (.md) // STEP 5: Generate testing report/table with results (.md)
//----------------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------------
#if defined(BUILD_TESTING_WEB)
const char *osName = "Web";
#else
#if defined(PLATFORM_DRM)
const char *osName = "DRM";
#elif defined(PLATFORM_DESKTOP)
#if defined(_WIN32)
const char *osName = "Windows";
#elif defined(__linux__)
const char *osName = "Linux";
#elif defined(__FreeBSD__)
const char *osName = "FreeBSD";
#elif defined(__APPLE__)
const char *osName = "macOS";
#endif // Desktop OSs
#endif
#endif
/* /*
Columns: Columns:
- [CWARN] : Compilation WARNING messages - [CWARN] : Compilation WARNING messages
@ -1697,7 +1719,7 @@ int main(int argc, char *argv[])
int repIndex = 0; int repIndex = 0;
repIndex += sprintf(report + repIndex, "# EXAMPLES COLLECTION - TESTING REPORT\n\n"); repIndex += sprintf(report + repIndex, "# EXAMPLES COLLECTION - TESTING REPORT\n\n");
repIndex += sprintf(report + repIndex, "## Tested Platform: Windows\n\n"); repIndex += sprintf(report + repIndex, TextFormat("## Tested Platform: %s\n\n", osName));
repIndex += sprintf(report + repIndex, "```\nExample automated testing elements validated:\n"); repIndex += sprintf(report + repIndex, "```\nExample automated testing elements validated:\n");
repIndex += sprintf(report + repIndex, " - [CWARN] : Compilation WARNING messages\n"); repIndex += sprintf(report + repIndex, " - [CWARN] : Compilation WARNING messages\n");
@ -1742,22 +1764,7 @@ int main(int argc, char *argv[])
repIndex += sprintf(report + repIndex, "\n"); repIndex += sprintf(report + repIndex, "\n");
#if defined(PLATFORM_DRM) SaveFileText(TextFormat("%s/../tools/rexm/reports/examples_testing_%s.md", exBasePath, TextToLower(osName)), report);
const char *osName = "drm";
#elif defined(PLATFORM_WEB)
const char *osName = "web";
#elif defined(PLATFORM_DESKTOP)
#if defined(_WIN32)
const char *osName = "windows";
#elif defined(__linux__)
const char *osName = "linux";
#elif defined(__FreeBSD__)
const char *osName = "freebsd";
#elif defined(__APPLE__)
const char *osName = "macos";
#endif // Desktop OSs
#endif
SaveFileText(TextFormat("%s/../tools/rexm/reports/examples_testing_%s.md", exBasePath, osName), report);
RL_FREE(report); RL_FREE(report);
//----------------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------------