File tree Expand file tree Collapse file tree 3 files changed +19
-5
lines changed Expand file tree Collapse file tree 3 files changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -50,10 +50,10 @@ else()
50
50
)
51
51
endif ()
52
52
53
- function (add_coverage_target name )
53
+ function (add_test_coverage_target name )
54
54
message (
55
55
STATUS
56
- "add_coverage_target (${name} ) is disabled because CMAKE_CXX_COMPILER_ID is ${CMAKE_CXX_COMPILER_ID} ."
56
+ "add_test_coverage_target (${name} ) is disabled because CMAKE_CXX_COMPILER_ID is ${CMAKE_CXX_COMPILER_ID} ."
57
57
)
58
58
endfunction ()
59
59
Original file line number Diff line number Diff line change @@ -229,7 +229,7 @@ endfunction()
229
229
230
230
function (add_python_test_target name )
231
231
set (multiValueArgs FILES INCLUDE_FILES INCLUDE_DIRECTORIES LIBRARIES
232
- EXTRA_ARGS)
232
+ EXTRA_ARGS EXTRA_DEPS )
233
233
cmake_parse_arguments (UNIT "" "" "${multiValueArgs} " ${ARGN} )
234
234
list (TRANSFORM UNIT_FILES PREPEND "${CMAKE_CURRENT_SOURCE_DIR} /" )
235
235
list (TRANSFORM UNIT_INCLUDE_FILES PREPEND "${CMAKE_CURRENT_SOURCE_DIR} /" )
@@ -253,13 +253,21 @@ function(add_python_test_target name)
253
253
string (PREPEND name "PYTHON." )
254
254
add_test (NAME ${name} COMMAND ${target_test_command} COMMAND_EXPAND_LISTS )
255
255
256
+ foreach (file ${UNIT_FILES} )
257
+ get_filename_component (this_dir ${file} DIRECTORY )
258
+ if (EXISTS "${this_dir} /conftest.py" )
259
+ list (APPEND auto_dependencies "${this_dir} /conftest.py" )
260
+ endif ()
261
+ endforeach ()
262
+
256
263
add_custom_target (all_${name} ALL DEPENDS run_${name} )
257
264
add_custom_target (run_${name} DEPENDS ${name} .passed)
258
265
add_custom_command (
259
266
OUTPUT ${name} .passed
260
267
COMMAND ${target_test_command}
261
268
COMMAND ${CMAKE_COMMAND} "-E" "touch" "${name} .passed"
262
- DEPENDS ${UNIT_FILES} ${UNIT_LIBRARIES}
269
+ DEPENDS ${UNIT_FILES} ${UNIT_LIBRARIES} ${UNIT_EXTRA_DEPS}
270
+ ${auto_dependencies}
263
271
COMMAND_EXPAND_LISTS )
264
272
265
273
add_dependencies (python_tests "run_${name} " )
Original file line number Diff line number Diff line change @@ -52,7 +52,8 @@ add_unit_test(
52
52
my_test
53
53
PYTEST
54
54
FILES my_test.py
55
- LIBRARIES my_lib)
55
+ LIBRARIES my_lib
56
+ EXTRA_DEPS my_header.hpp)
56
57
----
57
58
58
59
`add_unit_test` also supports running tests using https://pytest.org[pytest]. In
@@ -62,6 +63,11 @@ handled with pytest's
62
63
https://docs.pytest.org/en/8.0.x/reference/reference.html#pytest.hookspec.pytest_addoption[`addoption`
63
64
hook].
64
65
66
+ NOTE: The `EXTRA_DEPS` argument allows python tests to specify extra
67
+ dependencies that are not part of the CMake dependency tree. A `conftest.py`
68
+ file in the same directory as any of the `FILE`s is automatically discovered as
69
+ such a dependency.
70
+
65
71
=== Fuzz tests
66
72
67
73
[source,cmake]
You can’t perform that action at this time.
0 commit comments