@@ -19,18 +19,23 @@ endif()
19
19
# Only needed for CMake < 3.5 support
20
20
include (CMakeParseArguments)
21
21
22
- # Filter out items; print an optional message if any items filtered
22
+ # Filter out items; print an optional message if any items filtered. This ignores extensions.
23
23
#
24
24
# Usage:
25
25
# pybind11_filter_tests(LISTNAME file1.cpp file2.cpp ... MESSAGE "")
26
26
#
27
27
macro (pybind11_filter_tests LISTNAME)
28
28
cmake_parse_arguments (ARG "" "MESSAGE" "" ${ARGN} )
29
29
set (PYBIND11_FILTER_TESTS_FOUND OFF )
30
+ # Make a list of the test without any extensions, for easier filtering.
31
+ set (_TMP_ACTUAL_LIST "${${LISTNAME} };" ) # enforce ';' at the end to allow matching last item.
32
+ string (REGEX REPLACE "\\ .[^.]*;" ";" LIST_WITHOUT_EXTENSIONS "${_TMP_ACTUAL_LIST} " )
30
33
foreach (filename IN LISTS ARG_UNPARSED_ARGUMENTS)
31
- list (FIND ${LISTNAME} ${filename} _FILE_FOUND)
34
+ string (REGEX REPLACE "\\ .[^.]*$" "" filename_no_ext ${filename} )
35
+ # Search in the list without extensions.
36
+ list (FIND LIST_WITHOUT_EXTENSIONS ${filename_no_ext} _FILE_FOUND)
32
37
if (_FILE_FOUND GREATER -1)
33
- list (REMOVE_AT ${LISTNAME} ${_FILE_FOUND} )
38
+ list (REMOVE_AT ${LISTNAME} ${_FILE_FOUND} ) # And remove from the list with extensions.
34
39
set (PYBIND11_FILTER_TESTS_FOUND ON )
35
40
endif ()
36
41
endforeach ()
@@ -104,48 +109,64 @@ if(PYBIND11_CUDA_TESTS)
104
109
set (CMAKE_CUDA_STANDARD_REQUIRED ON )
105
110
endif ()
106
111
107
- # Full set of test files (you can override these; see below)
112
+ # Full set of test files (you can override these; see below, overrides ignore extension)
113
+ # Any test that has no extension is both .py and .cpp, so 'foo' will add 'foo.cpp' and 'foo.py'.
114
+ # Any test that has an extension is exclusively that and handled as such.
108
115
set (PYBIND11_TEST_FILES
109
- test_async.cpp
110
- test_buffers.cpp
111
- test_builtin_casters.cpp
112
- test_call_policies.cpp
113
- test_callbacks.cpp
114
- test_chrono.cpp
115
- test_class.cpp
116
- test_const_name.cpp
117
- test_constants_and_functions.cpp
118
- test_copy_move.cpp
119
- test_custom_type_casters.cpp
120
- test_custom_type_setup.cpp
121
- test_docstring_options.cpp
122
- test_eigen.cpp
123
- test_enum.cpp
124
- test_eval.cpp
125
- test_exceptions.cpp
126
- test_factory_constructors.cpp
127
- test_gil_scoped.cpp
128
- test_iostream.cpp
129
- test_kwargs_and_defaults.cpp
130
- test_local_bindings.cpp
131
- test_methods_and_attributes.cpp
132
- test_modules.cpp
133
- test_multiple_inheritance.cpp
134
- test_numpy_array.cpp
135
- test_numpy_dtypes.cpp
136
- test_numpy_vectorize.cpp
137
- test_opaque_types.cpp
138
- test_operator_overloading.cpp
139
- test_pickling.cpp
140
- test_pytypes.cpp
141
- test_sequences_and_iterators.cpp
142
- test_smart_ptr.cpp
143
- test_stl.cpp
144
- test_stl_binders.cpp
145
- test_tagbased_polymorphic.cpp
146
- test_thread.cpp
147
- test_union.cpp
148
- test_virtual_functions.cpp)
116
+ test_async
117
+ test_buffers
118
+ test_builtin_casters
119
+ test_call_policies
120
+ test_callbacks
121
+ test_chrono
122
+ test_class
123
+ test_class_sh_basic
124
+ test_class_sh_disowning
125
+ test_class_sh_disowning_mi
126
+ test_class_sh_factory_constructors
127
+ test_class_sh_inheritance
128
+ test_class_sh_shared_ptr_copy_move
129
+ test_class_sh_trampoline_basic
130
+ test_class_sh_trampoline_self_life_support
131
+ test_class_sh_trampoline_shared_from_this
132
+ test_class_sh_trampoline_shared_ptr_cpp_arg
133
+ test_class_sh_trampoline_unique_ptr
134
+ test_class_sh_unique_ptr_member
135
+ test_class_sh_virtual_py_cpp_mix
136
+ test_classh_mock
137
+ test_const_name
138
+ test_constants_and_functions
139
+ test_copy_move
140
+ test_custom_type_casters
141
+ test_custom_type_setup
142
+ test_docstring_options
143
+ test_eigen
144
+ test_enum
145
+ test_eval
146
+ test_exceptions
147
+ test_factory_constructors
148
+ test_gil_scoped
149
+ test_iostream
150
+ test_kwargs_and_defaults
151
+ test_local_bindings
152
+ test_methods_and_attributes
153
+ test_modules
154
+ test_multiple_inheritance
155
+ test_numpy_array
156
+ test_numpy_dtypes
157
+ test_numpy_vectorize
158
+ test_opaque_types
159
+ test_operator_overloading
160
+ test_pickling
161
+ test_pytypes
162
+ test_sequences_and_iterators
163
+ test_smart_ptr
164
+ test_stl
165
+ test_stl_binders
166
+ test_tagbased_polymorphic
167
+ test_thread
168
+ test_union
169
+ test_virtual_functions)
149
170
150
171
# Invoking cmake with something like:
151
172
# cmake -DPYBIND11_TEST_OVERRIDE="test_callbacks.cpp;test_pickling.cpp" ..
@@ -174,7 +195,25 @@ if(PYBIND11_CUDA_TESTS)
174
195
"Skipping test_constants_and_functions due to incompatible exception specifications" )
175
196
endif ()
176
197
177
- string (REPLACE ".cpp" ".py" PYBIND11_PYTEST_FILES "${PYBIND11_TEST_FILES} " )
198
+ # Now that the test filtering is complete, we need to split the list into the test for PYTEST
199
+ # and the list for the cpp targets.
200
+ set (PYBIND11_CPPTEST_FILES "" )
201
+ set (PYBIND11_PYTEST_FILES "" )
202
+
203
+ foreach (test_name ${PYBIND11_TEST_FILES} )
204
+ if (test_name MATCHES "\\ .py$" ) # Ends in .py, purely python test.
205
+ list (APPEND PYBIND11_PYTEST_FILES ${test_name} )
206
+ elseif (test_name MATCHES "\\ .cpp$" ) # Ends in .cpp, purely cpp test.
207
+ list (APPEND PYBIND11_CPPTEST_FILES ${test_name} )
208
+ elseif (NOT test_name MATCHES "\\ ." ) # No extension specified, assume both, add extension.
209
+ list (APPEND PYBIND11_PYTEST_FILES ${test_name} .py)
210
+ list (APPEND PYBIND11_CPPTEST_FILES ${test_name} .cpp)
211
+ else ()
212
+ message (WARNING "Unhanded test extension in test: ${test_name} " )
213
+ endif ()
214
+ endforeach ()
215
+ set (PYBIND11_TEST_FILES ${PYBIND11_CPPTEST_FILES} )
216
+ list (SORT PYBIND11_PYTEST_FILES)
178
217
179
218
# Contains the set of test files that require pybind11_cross_module_tests to be
180
219
# built; if none of these are built (i.e. because TEST_OVERRIDE is used and
@@ -366,7 +405,7 @@ set(test_targets pybind11_tests)
366
405
# Check if any tests need extra targets by iterating through the mappings registered.
367
406
foreach (i ${PYBIND11_TEST_EXTRA_TARGETS} )
368
407
foreach (needle ${PYBIND11_TEST_EXTRA_TARGETS_NEEDLES_${i} })
369
- if (${ needle} IN_LIST PYBIND11_PYTEST_FILES)
408
+ if (needle IN_LIST PYBIND11_PYTEST_FILES)
370
409
# Add all the additional targets to the test list. List join in newer cmake.
371
410
foreach (extra_target ${PYBIND11_TEST_EXTRA_TARGETS_ADDITION_${i} })
372
411
list (APPEND test_targets ${extra_target} )
0 commit comments