@@ -247,6 +247,7 @@ MACRO (NS_SERVER_TEST)
247
247
SET (_cmd "${CMAKE_COMMAND} " -D "ERL_EXECUTABLE=${ERL_EXECUTABLE} "
248
248
-D "COUCHDB_BIN_DIR=${COUCHDB_BIN_DIR} "
249
249
-D "TEST_TARGET=${_test_target} "
250
+ -D "TEST_FILTER=${TEST_FILTER} "
250
251
# We pass the CCACHE DIR to be able to load anything we need from the
251
252
# script. It otherwise wouldn't have access to those variables.
252
253
-D "CCACHE_DIR=${CMAKE_BINARY_DIR} "
@@ -263,6 +264,38 @@ MACRO (NS_SERVER_TEST)
263
264
ADD_DEPENDENCIES (${_name} ns_server_tests )
264
265
ENDMACRO (NS_SERVER_TEST )
265
266
267
+ function (discover_eunit_tests )
268
+ MESSAGE ("Discovering erlang files for eunit tests" )
269
+
270
+ ## Pull out all the .erl files from ns_server (we recurse the app folders).
271
+ ## CMake doesn't recommend using GLOB to do this, not all build systems
272
+ ## support GLOB/CONFIGURE_DEPENDS to re-run the cmake step when we add a
273
+ ## new file that matches the GLOB expression, but both make and ninja do
274
+ ## and I believe those are the only ones that we use at the moment. This
275
+ ## isn't the only place that we do this either...
276
+ FILE (GLOB_RECURSE ERL_FILES
277
+ CONFIGURE_DEPENDS
278
+ apps/*.erl )
279
+
280
+ foreach (FILE ${ERL_FILES} )
281
+ FILE (READ ${FILE} TMPTXT )
282
+
283
+ ## We only want to run ns_test for modules that have tests as
284
+ ## starting up erlang isn't particularly cheap (can take a couple of
285
+ ## seconds on my M2 Macbook Pro).
286
+ string (FIND "${TMPTXT} "
287
+ "-include_lib(\" eunit/include/eunit.hrl\" )." MATCH )
288
+ if (NOT ${MATCH} EQUAL -1 )
289
+ GET_FILENAME_COMPONENT (NAME_NO_EXT ${FILE} NAME_WLE )
290
+ SET (TEST_FILTER ${NAME_NO_EXT} )
291
+ NS_SERVER_TEST (NAME ns_test_${NAME_NO_EXT} TEST_TARGET start )
292
+ endif ()
293
+ endforeach (FILE ${ERL_FILES} )
294
+
295
+ endfunction (discover_eunit_tests )
296
+
297
+ discover_eunit_tests ()
298
+
266
299
NS_SERVER_TEST (NAME ns_test TEST_TARGET start )
267
300
NS_SERVER_TEST (NAME ns_test_eunit TEST_TARGET start_eunit EXPLICIT )
268
301
NS_SERVER_TEST (NAME ns_test_triq TEST_TARGET start_triq EXPLICIT )
0 commit comments