Skip to content

Commit d14b33f

Browse files
authored
🐛 Keep GoogleTest discovery artifacts in the build tree (#1954)
🤖 *AI text below* 🤖 ## Description CMake 4.3 writes a `cmake_test_discovery_*.json` bookkeeping file to the directory passed to `gtest_discover_tests(WORKING_DIRECTORY ...)`. Our test helpers passed source directories there because the same argument also controls the runtime working directory of each discovered test. As a result, configuring and building tests could dirty the source tree. Run GoogleTest discovery from the current binary directory so the bookkeeping file remains a build artifact. Preserve the existing runtime working directory by setting the discovered tests' `WORKING_DIRECTORY` property separately. The property name is deferred through a generator expression so CMake's argument parser does not interpret it as a second discovery option. This is extracted from #1912 because it is independent of the QDMI configuration work. ## Validation - Configured and built representative targets with CMake 4.3.2. - Confirmed that no `cmake_test_discovery_*.json` files appear outside `build/`. - Confirmed that the ordinary helper still runs a FoMaC test from its source directory. - Confirmed that the custom-working-directory helper still runs an IR test from its configured build directory. - `uvx nox -s lint` - `git diff --check` ## Checklist - [x] The pull request only contains commits that are focused and relevant to this change. - [x] I have added appropriate tests that cover the new/changed functionality. (Existing tests exercise both helper variants.) - [x] I have updated the documentation to reflect these changes. (No user-facing documentation change is needed.) - [x] I have added entries to the changelog for any noteworthy additions, changes, fixes, or removals. (Not user-facing.) - [x] I have added migration instructions to the upgrade guide (if needed). (No migration is needed.) - [x] The changes follow the project's style guidelines and introduce no new warnings. - [x] The changes are fully tested and pass the CI checks. (Local checks pass; CI is pending.) - [x] I have reviewed my own code changes. **If PR contains AI-assisted content:** - [x] Any agent that created, edited, or submitted GitHub content was explicitly authorized for that scope, as required by our [AI Usage Guidelines](https://github.com/munich-quantum-toolkit/core/blob/main/docs/ai_usage.md). - [x] Every agent-authored or agent-edited public text body begins with the visible disclosure `🤖 *AI text below* 🤖` (titles are exempt). - [x] AI-assisted commits include an `Assisted-by: [Model Name] via [Tool Name]` footer. - [x] I confirm that I have personally reviewed and understood all AI-generated content, and accept full responsibility for it.
1 parent 88d1caf commit d14b33f

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

cmake/PackageAddTest.cmake

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ macro(PACKAGE_ADD_TEST testname linklibs)
1919
# discover tests
2020
gtest_discover_tests(
2121
${testname}
22-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
23-
PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" DISCOVERY_TIMEOUT 60)
22+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
23+
# Defer the property name so it is not parsed as the discovery working directory.
24+
PROPERTIES "$<1:WORKING_DIRECTORY>" "${CMAKE_CURRENT_SOURCE_DIR}"
25+
VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" DISCOVERY_TIMEOUT 60)
2426
set_target_properties(${testname} PROPERTIES FOLDER tests)
2527

2628
# Set c++ standard
@@ -40,8 +42,10 @@ macro(PACKAGE_ADD_TEST_WITH_WORKING_DIR testname linklibs test_working_directory
4042
# discover tests
4143
gtest_discover_tests(
4244
${testname}
43-
WORKING_DIRECTORY ${test_working_directory}
44-
PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${test_working_directory}" DISCOVERY_TIMEOUT 60)
45+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
46+
# Defer the property name so it is not parsed as the discovery working directory.
47+
PROPERTIES "$<1:WORKING_DIRECTORY>" "${test_working_directory}" VS_DEBUGGER_WORKING_DIRECTORY
48+
"${test_working_directory}" DISCOVERY_TIMEOUT 60)
4549
set_target_properties(${testname} PROPERTIES FOLDER tests)
4650

4751
# Set c++ standard

0 commit comments

Comments
 (0)