-
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 all commits
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,20 @@ | ||
| # Editor-specific tests only. | ||
| # Shared test harness setup (doctest include, wine setup, mu_test_main, | ||
|
Comment on lines
+1
to
+2
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. Minor: stray leading space at the start of these two comment lines ( |
||
| # 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 "$<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 QUIET) | ||
| if(Python3_Interpreter_FOUND) | ||
| add_test(NAME test_editor_leak | ||
| COMMAND Python3::Interpreter ${CMAKE_CURRENT_SOURCE_DIR}/test_leak.py "${CMAKE_CURRENT_BINARY_DIR}/main_sources.txt") | ||
| else() | ||
|
Comment on lines
+14
to
+17
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. Minor: indentation here is 9 spaces vs 4 elsewhere in the file. Consistent 4-space indent inside the |
||
| message(STATUS "Skipping test_editor_leak: Python3 interpreter not found") | ||
|
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. If the Python 3 interpreter is not found, the leak test is silently skipped with a
Comment on lines
+12
to
+18
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. Silent skip defeats the regression guard. A guard test that disappears on hosts without Python3 is the worst of both worlds: green CI on those hosts, surprise red on hosts that have it. The whole point of this test is to be unconditional. I'd suggest dropping the Python dependency entirely and doing it in pure CMake - the logic is one regex check that if(NOT ENABLE_EDITOR)
file(GENERATE
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/main_sources.txt"
CONTENT "$<JOIN:$<TARGET_PROPERTY:Main,SOURCES>,\n>")
add_test(NAME test_editor_dir_not_in_main_sources
COMMAND ${CMAKE_COMMAND}
-DSOURCES_FILE=${CMAKE_CURRENT_BINARY_DIR}/main_sources.txt
-P ${CMAKE_CURRENT_SOURCE_DIR}/check_editor_leak.cmake)
endif()with file(STRINGS "${SOURCES_FILE}" sources)
set(leaked "")
foreach(s IN LISTS sources)
string(REPLACE "\\" "/" s_norm "${s}")
if(s_norm MATCHES "/MuEditor/")
list(APPEND leaked "${s}")
endif()
endforeach()
if(leaked)
message(FATAL_ERROR "MuEditor leaked into Main sources: ${leaked}")
endif()Self-contained, no language hop, no environment gap. If you prefer to keep Python, switch |
||
| endif() | ||
| 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.