]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Build tests with CTest in Cmake 4822/head
authorVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 19 Feb 2024 16:19:21 +0000 (16:19 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 19 Feb 2024 16:19:21 +0000 (16:19 +0000)
CMakeLists.txt
test/CMakeLists.txt

index 75455aae864a4174b52feb19f449b0d71d90f2c7..0671072a325de946967bb1c774f7d2ef47035378 100644 (file)
@@ -679,6 +679,7 @@ IF (ENABLE_CLANG_PLUGIN MATCHES "ON")
 ENDIF ()
 
 ADD_SUBDIRECTORY(src)
+enable_testing()
 ADD_SUBDIRECTORY(test)
 ADD_SUBDIRECTORY(utils)
 
index 08e9556f3ff8d9edea3007ccc9794994edf71e9b..67ff98050848f57d24beebfe5c96c21e47d86a86 100644 (file)
@@ -1,50 +1,56 @@
-SET(TESTSRC            rspamd_mem_pool_test.c
-                               rspamd_statfile_test.c
-                               rspamd_url_test.c
-                               rspamd_dns_test.c
-                               rspamd_dkim_test.c
-                               rspamd_rrd_test.c
-                               rspamd_radix_test.c
-                               rspamd_shingles_test.c
-                               rspamd_upstream_test.c
-                               rspamd_lua_pcall_vs_resume_test.c
-                               rspamd_lua_test.c
-                               rspamd_cryptobox_test.c
-                               rspamd_heap_test.c
-                               rspamd_test_suite.c)
+include(CTest)
 
-ADD_EXECUTABLE(rspamd-test EXCLUDE_FROM_ALL ${TESTSRC})
-SET_TARGET_PROPERTIES(rspamd-test PROPERTIES COMPILE_FLAGS "-DRSPAMD_TEST")
-ADD_DEPENDENCIES(rspamd-test rspamd-server)
-SET_TARGET_PROPERTIES(rspamd-test PROPERTIES LINKER_LANGUAGE CXX)
-TARGET_LINK_LIBRARIES(rspamd-test rspamd-server)
+IF(BUILD_TESTING MATCHES "ON")
+       SET(TESTSRC             rspamd_mem_pool_test.c
+                                       rspamd_statfile_test.c
+                                       rspamd_url_test.c
+                                       rspamd_dns_test.c
+                                       rspamd_dkim_test.c
+                                       rspamd_rrd_test.c
+                                       rspamd_radix_test.c
+                                       rspamd_shingles_test.c
+                                       rspamd_upstream_test.c
+                                       rspamd_lua_pcall_vs_resume_test.c
+                                       rspamd_lua_test.c
+                                       rspamd_cryptobox_test.c
+                                       rspamd_heap_test.c
+                                       rspamd_test_suite.c)
 
-SET(CXXTESTSSRC                rspamd_cxx_unit.cxx)
+       ADD_EXECUTABLE(rspamd-test ${TESTSRC})
+       SET_TARGET_PROPERTIES(rspamd-test PROPERTIES COMPILE_FLAGS "-DRSPAMD_TEST")
+       ADD_DEPENDENCIES(rspamd-test rspamd-server)
+       SET_TARGET_PROPERTIES(rspamd-test PROPERTIES LINKER_LANGUAGE CXX)
+       TARGET_LINK_LIBRARIES(rspamd-test rspamd-server)
+       ADD_TEST(NAME rspamd-test COMMAND rspamd-test "-p" "/rspamd/lua")
 
-ADD_EXECUTABLE(rspamd-test-cxx EXCLUDE_FROM_ALL ${CXXTESTSSRC})
-SET_TARGET_PROPERTIES(rspamd-test-cxx PROPERTIES LINKER_LANGUAGE CXX)
-ADD_DEPENDENCIES(rspamd-test-cxx rspamd-server)
-TARGET_LINK_LIBRARIES(rspamd-test-cxx PRIVATE rspamd-server)
-SET_TARGET_PROPERTIES(rspamd-test-cxx PROPERTIES LINKER_LANGUAGE CXX)
+       SET(CXXTESTSSRC         rspamd_cxx_unit.cxx)
 
-IF(NOT "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
-       # Also add dependencies for convenience
-       FILE(GLOB_RECURSE LUA_TESTS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/lua/*.*")
-       ADD_CUSTOM_TARGET(units-dir COMMAND
-               ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/lua/unit"
-       )
-       ADD_DEPENDENCIES(rspamd-test units-dir)
-       FOREACH(_LF IN LISTS LUA_TESTS)
-               GET_FILENAME_COMPONENT(_NM "${_LF}" NAME)
-               IF("${_LF}" MATCHES "^.*/unit/.*$")
-                       SET(_DS "${CMAKE_CURRENT_BINARY_DIR}/lua/unit/${_NM}")
-               ELSE()
-                       SET(_DS "${CMAKE_CURRENT_BINARY_DIR}/lua/${_NM}")
-               ENDIF()
-               ADD_CUSTOM_TARGET("${_NM}" COMMAND
-                       ${CMAKE_COMMAND} -E copy_if_different ${_LF} ${_DS}
-                       SOURCES "${_LF}"
+       ADD_EXECUTABLE(rspamd-test-cxx ${CXXTESTSSRC})
+       SET_TARGET_PROPERTIES(rspamd-test-cxx PROPERTIES LINKER_LANGUAGE CXX)
+       ADD_DEPENDENCIES(rspamd-test-cxx rspamd-server)
+       TARGET_LINK_LIBRARIES(rspamd-test-cxx PRIVATE rspamd-server)
+       SET_TARGET_PROPERTIES(rspamd-test-cxx PROPERTIES LINKER_LANGUAGE CXX)
+       ADD_TEST(NAME rspamd-test-cxx COMMAND rspamd-test-cxx)
+
+       IF(NOT "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
+               # Also add dependencies for convenience
+               FILE(GLOB_RECURSE LUA_TESTS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/lua/*.*")
+               ADD_CUSTOM_TARGET(units-dir COMMAND
+                       ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/lua/unit"
                )
-               ADD_DEPENDENCIES(rspamd-test "${_NM}")
-       ENDFOREACH()
+               ADD_DEPENDENCIES(rspamd-test units-dir)
+               FOREACH(_LF IN LISTS LUA_TESTS)
+                       GET_FILENAME_COMPONENT(_NM "${_LF}" NAME)
+                       IF("${_LF}" MATCHES "^.*/unit/.*$")
+                               SET(_DS "${CMAKE_CURRENT_BINARY_DIR}/lua/unit/${_NM}")
+                       ELSE()
+                               SET(_DS "${CMAKE_CURRENT_BINARY_DIR}/lua/${_NM}")
+                       ENDIF()
+                       ADD_CUSTOM_TARGET("${_NM}" COMMAND
+                               ${CMAKE_COMMAND} -E copy_if_different ${_LF} ${_DS}
+                               SOURCES "${_LF}"
+                       )
+                       ADD_DEPENDENCIES(rspamd-test "${_NM}")
+               ENDFOREACH()
+       ENDIF()
 ENDIF()
\ No newline at end of file