Skip to content

Commit 33cee11

Browse files
committed
REXM: REVIEWED: Automated testing for Web
1 parent 8081d2b commit 33cee11

File tree

1 file changed

+38
-31
lines changed

1 file changed

+38
-31
lines changed

tools/rexm/rexm.c

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,9 @@ int main(int argc, char *argv[])
14911491

14921492
LOG("INFO: [%i/%i] Testing example: [%s]\n", i + 1, exBuildListCount, exName);
14931493

1494+
// Create directory for logs (build and run logs)
1495+
MakeDirectory(TextFormat("%s/%s/logs", exBasePath, exCategory));
1496+
14941497
// Steps to follow
14951498
// STEP 1: Load example.c and replace required code to inject basic testing code: frames to run
14961499
// 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[])
15101513
TextFormat("%s/%s/%s.original.c", exBasePath, exCategory, exName));
15111514
char *srcText = LoadFileText(TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName));
15121515

1513-
//#define BUILD_TESTING_WEB
1516+
#define BUILD_TESTING_WEB
15141517
#if defined(BUILD_TESTING_WEB)
15151518
static const char *mainReplaceText =
15161519
"#include <stdio.h>\n"
@@ -1557,21 +1560,22 @@ int main(int argc, char *argv[])
15571560
// Build: raylib.com/examples/<category>/<category>_example_name.data
15581561
// Build: raylib.com/examples/<category>/<category>_example_name.wasm
15591562
// Build: raylib.com/examples/<category>/<category>_example_name.js
1560-
#if defined(_WIN32)
1563+
#if defined(_WIN32)
15611564
LOG("INFO: [%s] Building example for PLATFORM_WEB (Host: Win32)\n", exName);
1562-
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));
1563-
#else
1565+
system(TextFormat("mingw32-make -C %s -f Makefile.Web %s/%s PLATFORM=PLATFORM_WEB -B > %s/%s/logs/%s.build.log 2>&1",
1566+
exBasePath, exCategory, exName, exBasePath, exCategory, exName));
1567+
#else
15641568
LOG("INFO: [%s] Building example for PLATFORM_WEB (Host: POSIX)\n", exName);
15651569
system(TextFormat("make -C %s -f Makefile.Web %s/%s PLATFORM=PLATFORM_WEB -B", exBasePath, exCategory, exName));
1566-
#endif
1570+
#endif
15671571
// Restore original source code before continue
15681572
FileCopy(TextFormat("%s/%s/%s.original.c", exBasePath, exCategory, exName),
15691573
TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName));
15701574
FileRemove(TextFormat("%s/%s/%s.original.c", exBasePath, exCategory, exName));
15711575

15721576
// STEP 3: Run example on browser
15731577
ChangeDirectory(TextFormat("%s/%s", exBasePath, exCategory));
1574-
system("start python -m http.server 8080"); // TODO: Init localhost just once!
1578+
if (i == 0) system("start python -m http.server 8080"); // TODO: Init localhost just once!
15751579
system(TextFormat("start explorer \"http:\\localhost:8080/%s.html", exName));
15761580

15771581
// NOTE: Example .log is automatically downloaded into system Downloads directory on browser-example exectution
@@ -1595,22 +1599,20 @@ int main(int argc, char *argv[])
15951599
SaveFileText(TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName), srcTextUpdated[2]);
15961600
for (int i = 0; i < 3; i++) { MemFree(srcTextUpdated[i]); srcTextUpdated[i] = NULL; }
15971601

1598-
MakeDirectory(TextFormat("%s/%s/logs", exBasePath, exCategory));
1599-
16001602
// STEP 2: Build example for DESKTOP platform
1601-
#if defined(_WIN32)
1603+
#if defined(_WIN32)
16021604
// Set required environment variables
16031605
//putenv(TextFormat("RAYLIB_DIR=%s\\..", exBasePath));
16041606
_putenv("PATH=%PATH%;C:\\raylib\\w64devkit\\bin");
16051607
//putenv("MAKE=mingw32-make");
16061608
//ChangeDirectory(exBasePath);
1607-
#endif
1609+
#endif
16081610
// Build example for PLATFORM_DESKTOP
1609-
#if defined(_WIN32)
1611+
#if defined(_WIN32)
16101612
LOG("INFO: [%s] Building example for PLATFORM_DESKTOP (Host: Win32)\n", exName);
16111613
system(TextFormat("mingw32-make -C %s %s/%s PLATFORM=PLATFORM_DESKTOP -B > %s/%s/logs/%s.build.log 2>&1",
16121614
exBasePath, exCategory, exName, exBasePath, exCategory, exName));
1613-
#else
1615+
#else
16141616
LOG("INFO: [%s] Building example for PLATFORM_DESKTOP (Host: POSIX)\n", exName);
16151617
system(TextFormat("make -C %s %s/%s PLATFORM=PLATFORM_DESKTOP -B", exBasePath, exCategory, exName));
16161618
#endif
@@ -1623,7 +1625,7 @@ int main(int argc, char *argv[])
16231625
// NOTE: Not easy to retrieve process return value from system(), it's platform dependant
16241626
ChangeDirectory(TextFormat("%s/%s", exBasePath, exCategory));
16251627
system(TextFormat("%s --frames 2 > logs/%s.log", exName, exName));
1626-
1628+
#endif
16271629
// STEP 4: Load and validate log info
16281630
//---------------------------------------------------------------------------------------------
16291631
// Load <example_name>.build.log to check for compilation warnings
@@ -1640,7 +1642,11 @@ int main(int argc, char *argv[])
16401642
UnloadTextLines(exTestBuildLogLines, exTestBuildLogLinesCount);
16411643
UnloadFileText(exTestBuildLog);
16421644

1645+
#if defined(BUILD_TESTING_WEB)
1646+
char *exTestLog = LoadFileText(TextFormat("C:/Users/raysa/Downloads/%s.log", exName));
1647+
#else
16431648
char *exTestLog = LoadFileText(TextFormat("%s/%s/logs/%s.log", exBasePath, exCategory, exName));
1649+
#endif
16441650
int exTestLogLinesCount = 0;
16451651
char **exTestLogLines = LoadTextLines(exTestLog, &exTestLogLinesCount);
16461652

@@ -1670,11 +1676,27 @@ int main(int argc, char *argv[])
16701676
UnloadTextLines(exTestLogLines, exTestLogLinesCount);
16711677
UnloadFileText(exTestLog);
16721678
//---------------------------------------------------------------------------------------------
1673-
#endif
16741679
}
16751680

16761681
// STEP 5: Generate testing report/table with results (.md)
16771682
//-----------------------------------------------------------------------------------------------------
1683+
#if defined(BUILD_TESTING_WEB)
1684+
const char *osName = "Web";
1685+
#else
1686+
#if defined(PLATFORM_DRM)
1687+
const char *osName = "DRM";
1688+
#elif defined(PLATFORM_DESKTOP)
1689+
#if defined(_WIN32)
1690+
const char *osName = "Windows";
1691+
#elif defined(__linux__)
1692+
const char *osName = "Linux";
1693+
#elif defined(__FreeBSD__)
1694+
const char *osName = "FreeBSD";
1695+
#elif defined(__APPLE__)
1696+
const char *osName = "macOS";
1697+
#endif // Desktop OSs
1698+
#endif
1699+
#endif
16781700
/*
16791701
Columns:
16801702
- [CWARN] : Compilation WARNING messages
@@ -1697,7 +1719,7 @@ int main(int argc, char *argv[])
16971719

16981720
int repIndex = 0;
16991721
repIndex += sprintf(report + repIndex, "# EXAMPLES COLLECTION - TESTING REPORT\n\n");
1700-
repIndex += sprintf(report + repIndex, "## Tested Platform: Windows\n\n");
1722+
repIndex += sprintf(report + repIndex, TextFormat("## Tested Platform: %s\n\n", osName));
17011723

17021724
repIndex += sprintf(report + repIndex, "```\nExample automated testing elements validated:\n");
17031725
repIndex += sprintf(report + repIndex, " - [CWARN] : Compilation WARNING messages\n");
@@ -1742,22 +1764,7 @@ int main(int argc, char *argv[])
17421764

17431765
repIndex += sprintf(report + repIndex, "\n");
17441766

1745-
#if defined(PLATFORM_DRM)
1746-
const char *osName = "drm";
1747-
#elif defined(PLATFORM_WEB)
1748-
const char *osName = "web";
1749-
#elif defined(PLATFORM_DESKTOP)
1750-
#if defined(_WIN32)
1751-
const char *osName = "windows";
1752-
#elif defined(__linux__)
1753-
const char *osName = "linux";
1754-
#elif defined(__FreeBSD__)
1755-
const char *osName = "freebsd";
1756-
#elif defined(__APPLE__)
1757-
const char *osName = "macos";
1758-
#endif // Desktop OSs
1759-
#endif
1760-
SaveFileText(TextFormat("%s/../tools/rexm/reports/examples_testing_%s.md", exBasePath, osName), report);
1767+
SaveFileText(TextFormat("%s/../tools/rexm/reports/examples_testing_%s.md", exBasePath, TextToLower(osName)), report);
17611768

17621769
RL_FREE(report);
17631770
//-----------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)