From 4b4d0745c838e9720cfabf67c9b4820659d24666 Mon Sep 17 00:00:00 2001 From: Piyush Gupta Date: Sun, 3 May 2026 10:53:49 +0530 Subject: [PATCH 1/4] Add test to ensure MuEditor is removed when flag is off (#359) --- src/.gitignore | 1 - tests/CMakeLists.txt | 2 ++ tests/editor/CMakeLists.txt | 66 +++++++++++++++++++++++++++++++++++++ tests/editor/test_leak.py | 28 ++++++++++++++++ 4 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 tests/editor/CMakeLists.txt create mode 100644 tests/editor/test_leak.py diff --git a/src/.gitignore b/src/.gitignore index 98fd65a92a..ba0c9511b2 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -4,7 +4,6 @@ /*.dat *.sdf .tmp/ -.tmp\ *.bak *.sbr *.tlog diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b10a8f8eca..dbacc79901 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -51,3 +51,5 @@ function(mu_add_test) endfunction() add_subdirectory(text) + +add_subdirectory(editor) diff --git a/tests/editor/CMakeLists.txt b/tests/editor/CMakeLists.txt new file mode 100644 index 0000000000..72848930ac --- /dev/null +++ b/tests/editor/CMakeLists.txt @@ -0,0 +1,66 @@ +# Test tree. New test modules go in their own subdirectory and call +# add_subdirectory() below. Keep the entry point here minimal — module +# CMakeLists.txt files own their own sources, link, and call mu_add_test(). + +include(third_party/doctest/doctest.cmake) + +# When cross-compiling Windows binaries on a non-Windows host (CI's Linux +# runner, WSL/MinGW), wine has to launch the .exe. Setting this once makes +# both add_test and doctest_discover_tests pick it up via the +# CROSSCOMPILING_EMULATOR target property. +if(WIN32 AND NOT CMAKE_HOST_WIN32 AND NOT CMAKE_CROSSCOMPILING_EMULATOR) + find_program(WINE_EXECUTABLE wine) + if(NOT WINE_EXECUTABLE) + message(FATAL_ERROR + "BUILD_TESTING=ON on a non-Windows host requires wine to run " + "the cross-compiled test binaries. Install it (Ubuntu/Debian: " + "sudo apt-get install wine wine32) or configure with " + "-DBUILD_TESTING=OFF.") + endif() + set(CMAKE_CROSSCOMPILING_EMULATOR ${WINE_EXECUTABLE} CACHE STRING "" FORCE) +endif() + +add_library(mu_test_main STATIC main.cpp) +target_include_directories(mu_test_main PUBLIC third_party/doctest) +target_compile_features(mu_test_main PUBLIC cxx_std_20) +# Test sources contain non-ASCII wide string literals. MSVC defaults to the +# system codepage when reading sources, which mangles UTF-8 characters into +# wrong codepoints and breaks every non-Latin language test. /utf-8 forces +# both the source charset and the narrow execution charset to UTF-8; the wide +# execution charset stays UTF-16 (Windows wchar_t). +if(MSVC) + target_compile_options(mu_test_main PUBLIC /utf-8) +endif() + +# Helper for module CMakeLists. Usage: +# mu_add_test(NAME SOURCES a.cpp b.cpp LINK_LIBS lib1 lib2) +# Registers each TEST_CASE inside the binary as its own CTest entry, so +# failures point at the specific case in CI logs. +function(mu_add_test) + cmake_parse_arguments(MAT "" "NAME" "SOURCES;LINK_LIBS" ${ARGN}) + add_executable(${MAT_NAME} ${MAT_SOURCES}) + target_link_libraries(${MAT_NAME} PRIVATE mu_test_main ${MAT_LINK_LIBS}) + target_include_directories(${MAT_NAME} PRIVATE + ${CMAKE_SOURCE_DIR}/src/source + ${CMAKE_CURRENT_SOURCE_DIR}/third_party/doctest + ) + if(MSVC) + target_compile_options(${MAT_NAME} PRIVATE /utf-8) + endif() + doctest_discover_tests(${MAT_NAME}) +endfunction() + +add_subdirectory(text) + +# Add Editor Leak Test (only runs when ENABLE_EDITOR is OFF) +if(NOT ENABLE_EDITOR) + # Generate a text file containing all sources of the Main target + file(GENERATE + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/main_sources.txt" + CONTENT "$,\n>") + + # Add a test that runs a Python script to verify MuEditor isn't in those sources + find_package(Python3 COMPONENTS Interpreter REQUIRED) + add_test(NAME test_editor_leak + COMMAND Python3::Interpreter ${CMAKE_CURRENT_SOURCE_DIR}/editor/test_leak.py "${CMAKE_CURRENT_BINARY_DIR}/main_sources.txt") +endif() diff --git a/tests/editor/test_leak.py b/tests/editor/test_leak.py new file mode 100644 index 0000000000..c1a2761b17 --- /dev/null +++ b/tests/editor/test_leak.py @@ -0,0 +1,28 @@ +import sys + +def main(): + if len(sys.argv) < 2: + print("Usage: test_leak.py ") + sys.exit(1) + + sources_file = sys.argv[1] + + with open(sources_file, 'r', encoding='utf-8') as f: + sources = f.read().splitlines() + + # Normalise to forward slashes so the path-segment check is + # platform-independent and won't fire just because the repository + # happens to be cloned inside a directory called "MuEditor". + leaked_files = [s for s in sources if '/MuEditor/' in s.replace('\\', '/')] + + if leaked_files: + print("FAIL: MuEditor leaked into the build! The following editor files were found in the Main target sources:") + for f in leaked_files: + print(f" - {f}") + sys.exit(1) + else: + print("PASS: No MuEditor files leaked into the build.") + sys.exit(0) + +if __name__ == '__main__': + main() From f0d9b9c03bce75cbcf749d42a3cc9f53bb418fbd Mon Sep 17 00:00:00 2001 From: Piyush Gupta <108690773+guptapiyush16@users.noreply.github.com> Date: Wed, 6 May 2026 19:33:14 +0530 Subject: [PATCH 2/4] Update CMakeLists.txt --- tests/editor/CMakeLists.txt | 66 +++++-------------------------------- 1 file changed, 8 insertions(+), 58 deletions(-) diff --git a/tests/editor/CMakeLists.txt b/tests/editor/CMakeLists.txt index 72848930ac..76061f3b26 100644 --- a/tests/editor/CMakeLists.txt +++ b/tests/editor/CMakeLists.txt @@ -1,66 +1,16 @@ -# Test tree. New test modules go in their own subdirectory and call -# add_subdirectory() below. Keep the entry point here minimal — module -# CMakeLists.txt files own their own sources, link, and call mu_add_test(). - -include(third_party/doctest/doctest.cmake) - -# When cross-compiling Windows binaries on a non-Windows host (CI's Linux -# runner, WSL/MinGW), wine has to launch the .exe. Setting this once makes -# both add_test and doctest_discover_tests pick it up via the -# CROSSCOMPILING_EMULATOR target property. -if(WIN32 AND NOT CMAKE_HOST_WIN32 AND NOT CMAKE_CROSSCOMPILING_EMULATOR) - find_program(WINE_EXECUTABLE wine) - if(NOT WINE_EXECUTABLE) - message(FATAL_ERROR - "BUILD_TESTING=ON on a non-Windows host requires wine to run " - "the cross-compiled test binaries. Install it (Ubuntu/Debian: " - "sudo apt-get install wine wine32) or configure with " - "-DBUILD_TESTING=OFF.") - endif() - set(CMAKE_CROSSCOMPILING_EMULATOR ${WINE_EXECUTABLE} CACHE STRING "" FORCE) -endif() - -add_library(mu_test_main STATIC main.cpp) -target_include_directories(mu_test_main PUBLIC third_party/doctest) -target_compile_features(mu_test_main PUBLIC cxx_std_20) -# Test sources contain non-ASCII wide string literals. MSVC defaults to the -# system codepage when reading sources, which mangles UTF-8 characters into -# wrong codepoints and breaks every non-Latin language test. /utf-8 forces -# both the source charset and the narrow execution charset to UTF-8; the wide -# execution charset stays UTF-16 (Windows wchar_t). -if(MSVC) - target_compile_options(mu_test_main PUBLIC /utf-8) -endif() - -# Helper for module CMakeLists. Usage: -# mu_add_test(NAME SOURCES a.cpp b.cpp LINK_LIBS lib1 lib2) -# Registers each TEST_CASE inside the binary as its own CTest entry, so -# failures point at the specific case in CI logs. -function(mu_add_test) - cmake_parse_arguments(MAT "" "NAME" "SOURCES;LINK_LIBS" ${ARGN}) - add_executable(${MAT_NAME} ${MAT_SOURCES}) - target_link_libraries(${MAT_NAME} PRIVATE mu_test_main ${MAT_LINK_LIBS}) - target_include_directories(${MAT_NAME} PRIVATE - ${CMAKE_SOURCE_DIR}/src/source - ${CMAKE_CURRENT_SOURCE_DIR}/third_party/doctest - ) - if(MSVC) - target_compile_options(${MAT_NAME} PRIVATE /utf-8) - endif() - doctest_discover_tests(${MAT_NAME}) -endfunction() - -add_subdirectory(text) + # Editor-specific tests only. + # Shared test harness setup (doctest include, wine setup, mu_test_main, + # and mu_add_test) must remain in the top-level tests/CMakeLists.txt. # Add Editor Leak Test (only runs when ENABLE_EDITOR is OFF) if(NOT ENABLE_EDITOR) # Generate a text file containing all sources of the Main target - file(GENERATE - OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/main_sources.txt" - CONTENT "$,\n>") + file(GENERATE + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/main_sources.txt" + CONTENT "$,\n>") # Add a test that runs a Python script to verify MuEditor isn't in those sources find_package(Python3 COMPONENTS Interpreter REQUIRED) - add_test(NAME test_editor_leak - COMMAND Python3::Interpreter ${CMAKE_CURRENT_SOURCE_DIR}/editor/test_leak.py "${CMAKE_CURRENT_BINARY_DIR}/main_sources.txt") + add_test(NAME test_editor_leak + COMMAND Python3::Interpreter ${CMAKE_CURRENT_SOURCE_DIR}/editor/test_leak.py "${CMAKE_CURRENT_BINARY_DIR}/main_sources.txt") endif() From dd99b6869161adc1feb798638b275e4aaf60fb8f Mon Sep 17 00:00:00 2001 From: Piyush Gupta <108690773+guptapiyush16@users.noreply.github.com> Date: Wed, 6 May 2026 19:54:15 +0530 Subject: [PATCH 3/4] Update CMakeLists.txt --- tests/editor/CMakeLists.txt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/editor/CMakeLists.txt b/tests/editor/CMakeLists.txt index 76061f3b26..91d3f00e12 100644 --- a/tests/editor/CMakeLists.txt +++ b/tests/editor/CMakeLists.txt @@ -10,7 +10,11 @@ if(NOT ENABLE_EDITOR) CONTENT "$,\n>") # Add a test that runs a Python script to verify MuEditor isn't in those sources - find_package(Python3 COMPONENTS Interpreter REQUIRED) - add_test(NAME test_editor_leak - COMMAND Python3::Interpreter ${CMAKE_CURRENT_SOURCE_DIR}/editor/test_leak.py "${CMAKE_CURRENT_BINARY_DIR}/main_sources.txt") + find_package(Python3 COMPONENTS Interpreter QUIET) + if(Python3_Interpreter_FOUND) + add_test(NAME test_editor_leak + COMMAND Python3::Interpreter ${CMAKE_CURRENT_SOURCE_DIR}/editor/test_leak.py "${CMAKE_CURRENT_BINARY_DIR}/main_sources.txt") + else() + message(STATUS "Skipping test_editor_leak: Python3 interpreter not found") + endif() endif() From 8b3f3fd7756e548e24f30da902716c108d8b2614 Mon Sep 17 00:00:00 2001 From: Piyush Gupta <108690773+guptapiyush16@users.noreply.github.com> Date: Wed, 6 May 2026 20:41:12 +0530 Subject: [PATCH 4/4] Update CMakeLists.txt --- tests/editor/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/editor/CMakeLists.txt b/tests/editor/CMakeLists.txt index 91d3f00e12..7b0630f742 100644 --- a/tests/editor/CMakeLists.txt +++ b/tests/editor/CMakeLists.txt @@ -13,7 +13,7 @@ if(NOT ENABLE_EDITOR) find_package(Python3 COMPONENTS Interpreter QUIET) if(Python3_Interpreter_FOUND) add_test(NAME test_editor_leak - COMMAND Python3::Interpreter ${CMAKE_CURRENT_SOURCE_DIR}/editor/test_leak.py "${CMAKE_CURRENT_BINARY_DIR}/main_sources.txt") + COMMAND Python3::Interpreter ${CMAKE_CURRENT_SOURCE_DIR}/test_leak.py "${CMAKE_CURRENT_BINARY_DIR}/main_sources.txt") else() message(STATUS "Skipping test_editor_leak: Python3 interpreter not found") endif()