Refactor test configuration in CMake to enable conditional test builds

- Updated `CMakeLists.txt` to conditionally build the test executable based on the `YAZE_BUILD_TESTS` flag, enhancing flexibility in test management.
- Removed hardcoded test executable configurations and replaced them with conditional logic for minimal and development builds.
- Improved organization of test files and dependencies, ensuring that tests are only built and discovered when enabled, streamlining the build process.
This commit is contained in:
scawful
2025-09-28 16:25:40 -04:00
parent 46a8590b7f
commit 9066c8a3c0
2 changed files with 159 additions and 154 deletions

View File

@@ -235,7 +235,6 @@ jobs:
-DYAZE_ENABLE_EXPERIMENTAL_TESTS=OFF ` -DYAZE_ENABLE_EXPERIMENTAL_TESTS=OFF `
-DYAZE_INSTALL_LIB=OFF ` -DYAZE_INSTALL_LIB=OFF `
-DYAZE_MINIMAL_BUILD=OFF ` -DYAZE_MINIMAL_BUILD=OFF `
-DGTEST_DISCOVER_TESTS_DISCOVERY_MODE=POST_BUILD `
-G "${{ matrix.cmake_generator }}" ` -G "${{ matrix.cmake_generator }}" `
-A ${{ matrix.cmake_generator_platform }} -A ${{ matrix.cmake_generator_platform }}
} else { } else {
@@ -249,7 +248,6 @@ jobs:
-DYAZE_ENABLE_EXPERIMENTAL_TESTS=OFF ` -DYAZE_ENABLE_EXPERIMENTAL_TESTS=OFF `
-DYAZE_INSTALL_LIB=OFF ` -DYAZE_INSTALL_LIB=OFF `
-DYAZE_MINIMAL_BUILD=ON ` -DYAZE_MINIMAL_BUILD=ON `
-DGTEST_DISCOVER_TESTS_DISCOVERY_MODE=POST_BUILD `
-G "${{ matrix.cmake_generator }}" ` -G "${{ matrix.cmake_generator }}" `
-A ${{ matrix.cmake_generator_platform }} -A ${{ matrix.cmake_generator_platform }}
} }

View File

@@ -11,6 +11,8 @@ foreach (file
list(APPEND YAZE_SRC_FILES ${CMAKE_SOURCE_DIR}/src/${file}) list(APPEND YAZE_SRC_FILES ${CMAKE_SOURCE_DIR}/src/${file})
endforeach() endforeach()
# Only build test executable if tests are enabled
if(YAZE_BUILD_TESTS)
# Main test executable with enhanced argument handling for AI agents # Main test executable with enhanced argument handling for AI agents
# Use CI version for minimal builds, full version for development # Use CI version for minimal builds, full version for development
if(YAZE_MINIMAL_BUILD) if(YAZE_MINIMAL_BUILD)
@@ -153,6 +155,7 @@ if(NOT YAZE_MINIMAL_BUILD AND YAZE_ENABLE_ROM_TESTS)
endif() endif()
endif() endif()
# Configure test executable only when tests are enabled
target_include_directories( target_include_directories(
yaze_test PUBLIC yaze_test PUBLIC
${CMAKE_SOURCE_DIR}/src/app/ ${CMAKE_SOURCE_DIR}/src/app/
@@ -211,6 +214,7 @@ elseif(APPLE)
elseif(WIN32) elseif(WIN32)
target_compile_definitions(yaze_test PRIVATE "WINDOWS") target_compile_definitions(yaze_test PRIVATE "WINDOWS")
endif() endif()
endif()
# Configure test discovery with efficient labeling for CI/CD # Configure test discovery with efficient labeling for CI/CD
# Only discover tests if tests are enabled # Only discover tests if tests are enabled
@@ -219,6 +223,9 @@ if(YAZE_BUILD_TESTS)
# Discover all tests with default properties # Discover all tests with default properties
gtest_discover_tests(yaze_test) gtest_discover_tests(yaze_test)
else()
# Tests are disabled - don't build test executable or discover tests
message(STATUS "Tests disabled - skipping test executable and discovery")
endif() endif()
# Test organization and labeling for CI/CD # Test organization and labeling for CI/CD