Skip to content

Commit

Permalink
tests: allow platform specific unit test files
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher committed Apr 17, 2024
1 parent 3a42a59 commit 2c12c81
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
32 changes: 29 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,42 @@ if (WIN32)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # cmake-lint: disable=C0103
endif ()

set(TEST_PATTERNS test_* mock_*)
file(GLOB_RECURSE TEST_SOURCES
${CMAKE_SOURCE_DIR}/tests/conftest.cpp
${CMAKE_SOURCE_DIR}/tests/utils.cpp
${CMAKE_SOURCE_DIR}/tests/test_*.cpp)
"${CMAKE_SOURCE_DIR}/tests/conftest.cpp"
"${CMAKE_SOURCE_DIR}/tests/utils.cpp")
set(TEST_PLATFORM_SOURCES)

foreach(PATTERN ${TEST_PATTERNS})
file(GLOB_RECURSE CURRENT_TEST_SOURCES
"${CMAKE_SOURCE_DIR}/tests/${PATTERN}.cpp")
list(APPEND TEST_SOURCES ${CURRENT_TEST_SOURCES})

if(WIN32)
file(GLOB_RECURSE CURRENT_TEST_PLATFORM_SOURCES
"${CMAKE_SOURCE_DIR}/tests/*/platf/windows/${PATTERN}.cpp")
elseif(__APPLE__)
file(GLOB_RECURSE CURRENT_TEST_PLATFORM_SOURCES
"${CMAKE_SOURCE_DIR}/tests/*/platf/macos/${PATTERN}.cpp")
elseif(UNIX)
file(GLOB_RECURSE CURRENT_TEST_PLATFORM_SOURCES
"${CMAKE_SOURCE_DIR}/tests/*/platf/linux/${PATTERN}.cpp")
else()
message(FATAL_ERROR "Unsupported platform")
endif()

list(APPEND TEST_PLATFORM_SOURCES ${CURRENT_TEST_PLATFORM_SOURCES})
endforeach()

list(FILTER TEST_SOURCES EXCLUDE REGEX ".*/platf/.*")
message(STATUS "Common Test sources: ${TEST_SOURCES}")

set(DD_SOURCES
${DD_TARGET_FILES})

add_executable(${PROJECT_NAME}
${TEST_SOURCES}
${TEST_PLATFORM_SOURCES}
${DD_SOURCES})
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 20)
target_link_libraries(${PROJECT_NAME}
Expand Down
1 change: 1 addition & 0 deletions tests/unit/platf/linux/test_linux_sample.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TODO: remove this file
1 change: 1 addition & 0 deletions tests/unit/platf/macos/test_macos_sample.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TODO: remove this file
1 change: 1 addition & 0 deletions tests/unit/platf/windows/test_windows_sample.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TODO: remove this file

0 comments on commit 2c12c81

Please sign in to comment.