From f7cbf104c2968885c8f9dea3a26d3ace7db4d258 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Mon, 15 Apr 2024 17:32:19 -0400 Subject: [PATCH] tests: allow platform specific unit test files --- tests/CMakeLists.txt | 32 +++++++++++++++++-- tests/unit/platf/linux/test_linux_sample.cpp | 1 + tests/unit/platf/macos/test_macos_sample.cpp | 1 + .../platf/windows/test_windows_sample.cpp | 1 + 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 tests/unit/platf/linux/test_linux_sample.cpp create mode 100644 tests/unit/platf/macos/test_macos_sample.cpp create mode 100644 tests/unit/platf/windows/test_windows_sample.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 254c697..2a8fc3a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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} diff --git a/tests/unit/platf/linux/test_linux_sample.cpp b/tests/unit/platf/linux/test_linux_sample.cpp new file mode 100644 index 0000000..b186cfc --- /dev/null +++ b/tests/unit/platf/linux/test_linux_sample.cpp @@ -0,0 +1 @@ +// TODO: remove this file diff --git a/tests/unit/platf/macos/test_macos_sample.cpp b/tests/unit/platf/macos/test_macos_sample.cpp new file mode 100644 index 0000000..b186cfc --- /dev/null +++ b/tests/unit/platf/macos/test_macos_sample.cpp @@ -0,0 +1 @@ +// TODO: remove this file diff --git a/tests/unit/platf/windows/test_windows_sample.cpp b/tests/unit/platf/windows/test_windows_sample.cpp new file mode 100644 index 0000000..b186cfc --- /dev/null +++ b/tests/unit/platf/windows/test_windows_sample.cpp @@ -0,0 +1 @@ +// TODO: remove this file