Testing module

Signed-off-by: faumaray <faumaray@gmail.com>
This commit is contained in:
faumaray committed 2026-04-29 22:49:33 +03:00
1 parent 4fc129fb7e
commit e7186f17f0
42 files changed
+1816 -413

No files matched your search

+19 -24
View File
@@ -1,53 +1,48 @@
if(NOT VOID_ENABLE_TESTING)
message("Tests disabled")
return()
endif()
include(${CMAKE_SOURCE_DIR}/cmake/VoidTesting.cmake)
enable_testing()
# Get the list of modules that were actually successfully created
get_property(ACTIVE_MODULES GLOBAL PROPERTY VOID_MODULES)
# ------------------------------------------------------------------------------
# PART 1: Internal "Kitchen Sink" Test (One Executable to rule them all)
# PART 1: Internal kitchen-sink test (links every module).
# ------------------------------------------------------------------------------
file(GLOB_RECURSE INTERNAL_SOURCES CONFIGURE_DEPENDS "internal/*.cpp")
if(INTERNAL_SOURCES)
add_executable(VoidInternalTests ${INTERNAL_SOURCES})
# Always link the Testing framework
target_link_libraries(VoidInternalTests PRIVATE Void::Testing)
# Link against EVERY active module in the project
foreach(mod ${ACTIVE_MODULES})
# Avoid self-linking if Testing is in the list
if(NOT mod STREQUAL "Testing")
if(NOT mod STREQUAL "Testing" AND NOT mod STREQUAL "TestingMock")
target_link_libraries(VoidInternalTests PRIVATE Void::${mod})
endif()
endforeach()
add_test(NAME AllInternalTests COMMAND VoidInternalTests)
if(TARGET Void::TestingMock)
target_link_libraries(VoidInternalTests PRIVATE Void::TestingMock)
endif()
endif()
# ------------------------------------------------------------------------------
# PART 2: Standalone Tests (Isolated Executables per Module)
# PART 2: Standalone tests — one executable per source file under
# tests/standalone/<Module>/. Auto-scan picks each one up via the deferred
# sweep registered by cmake/VoidTesting.cmake.
# ------------------------------------------------------------------------------
foreach(mod ${ACTIVE_MODULES})
# Look for a subdirectory in standalone/ that matches the module name
set(STANDALONE_MOD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/standalone/${mod}")
if(IS_DIRECTORY ${STANDALONE_MOD_DIR})
file(GLOB test_files CONFIGURE_DEPENDS "${STANDALONE_MOD_DIR}/*.cpp")
foreach(test_src ${test_files})
get_filename_component(test_file_name ${test_src} NAME_WE)
set(EXE_NAME "test_standalone_${mod}_${test_file_name}")
add_executable(${EXE_NAME} ${test_src})
# Only links against its specific module
target_link_libraries(${EXE_NAME} PRIVATE Void::${mod})
add_test(NAME ${EXE_NAME} COMMAND ${EXE_NAME})
target_link_libraries(${EXE_NAME} PRIVATE Void::Testing)
if(NOT mod STREQUAL "Testing" AND NOT mod STREQUAL "TestingMock")
target_link_libraries(${EXE_NAME} PRIVATE Void::${mod})
endif()
if(TARGET Void::TestingMock)
target_link_libraries(${EXE_NAME} PRIVATE Void::TestingMock)
endif()
endforeach()
endif()
endforeach()