Skip to content

Commit 6ab9ffa

Browse files
authored
🚸 new test macro with customizable working directory (cda-tum#622)
## Description This tiny PR adds a new macro for explicitly setting the working directory for a googletest test suite. This can be useful for ensuring that files on the system are properly found in the tests. ## Checklist: <!--- This checklist serves as a reminder of a couple of things that ensure your pull request will be merged swiftly. --> - [x] The pull request only contains commits that are related to it. - [x] I have added appropriate tests and documentation. - [x] I have made sure that all CI jobs on GitHub pass. - [x] The pull request introduces no new warnings and follows the project's style guidelines. Signed-off-by: burgholzer <burgholzer@me.com>
1 parent 2a43c69 commit 6ab9ffa

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

cmake/PackageAddTest.cmake

+16
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,19 @@ macro(PACKAGE_ADD_TEST testname linklibs)
1414
set_target_properties(${testname} PROPERTIES FOLDER tests)
1515
endif()
1616
endmacro()
17+
18+
macro(PACKAGE_ADD_TEST_WITH_WORKING_DIR testname linklibs test_working_directory)
19+
if(NOT TARGET ${testname})
20+
# create an executable in which the tests will be stored
21+
add_executable(${testname} ${ARGN})
22+
# link the Google test infrastructure and a default main function to the test executable.
23+
target_link_libraries(${testname} PRIVATE ${linklibs} gmock gtest_main MQT::ProjectOptions
24+
MQT::ProjectWarnings)
25+
# discover tests
26+
gtest_discover_tests(
27+
${testname}
28+
WORKING_DIRECTORY ${test_working_directory}
29+
PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${test_working_directory}" DISCOVERY_TIMEOUT 60)
30+
set_target_properties(${testname} PROPERTIES FOLDER tests)
31+
endif()
32+
endmacro()

0 commit comments

Comments
 (0)