-
Notifications
You must be signed in to change notification settings - Fork 211
Add test to ensure MuEditor is removed when flag is off (#359) #362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,6 @@ | |
| /*.dat | ||
| *.sdf | ||
| .tmp/ | ||
| .tmp\ | ||
| *.bak | ||
| *.sbr | ||
| *.tlog | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,3 +51,5 @@ function(mu_add_test) | |
| endfunction() | ||
|
|
||
| add_subdirectory(text) | ||
|
|
||
| add_subdirectory(editor) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) | ||
|
|
||
|
Mosch0512 marked this conversation as resolved.
Outdated
|
||
| # 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() | ||
|
Mosch0512 marked this conversation as resolved.
Outdated
|
||
|
|
||
| # Helper for module CMakeLists. Usage: | ||
| # mu_add_test(NAME <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) | ||
|
|
||
|
Mosch0512 marked this conversation as resolved.
Outdated
|
||
| # 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 "$<JOIN:$<TARGET_PROPERTY:Main,SOURCES>,\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 | ||
|
Mosch0512 marked this conversation as resolved.
Outdated
|
||
| COMMAND Python3::Interpreter ${CMAKE_CURRENT_SOURCE_DIR}/editor/test_leak.py "${CMAKE_CURRENT_BINARY_DIR}/main_sources.txt") | ||
|
Mosch0512 marked this conversation as resolved.
Outdated
|
||
| endif() | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,28 @@ | ||||||||||||||||||||||
| import sys | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def main(): | ||||||||||||||||||||||
| if len(sys.argv) < 2: | ||||||||||||||||||||||
| print("Usage: test_leak.py <sources_file>") | ||||||||||||||||||||||
| 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('\\', '/')] | ||||||||||||||||||||||
|
Comment on lines
+13
to
+16
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current path matching logic is susceptible to false positives if the repository is cloned into a directory named
Suggested change
Comment on lines
+13
to
+16
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current check for To fix this, calculate the path of each source file relative to the project root and check if
Suggested change
Comment on lines
+13
to
+16
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test name overstates coverage. This catches file-path leaks (sources whose path contains Two options:
Either is fine - but the current name + scope mismatch will mislead future readers. |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| 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}") | ||||||||||||||||||||||
|
Comment on lines
+10
to
+21
|
||||||||||||||||||||||
| sys.exit(1) | ||||||||||||||||||||||
| else: | ||||||||||||||||||||||
| print("PASS: No MuEditor files leaked into the build.") | ||||||||||||||||||||||
| sys.exit(0) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if __name__ == '__main__': | ||||||||||||||||||||||
| main() | ||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated change.
This
.tmp\deletion isn't related to the editor-leak test. Perdocs/CODING_RULES.md§10 (keep diffs focused on one concern), please split this into its own commit or its own PR. The change itself is fine -.tmp\was never valid gitignore syntax, the.tmp/line above already handles the directory - but it doesn't belong here.