From 9b43c2b4e4066d20b5801f24b645140e6422c7ce Mon Sep 17 00:00:00 2001 From: scawful Date: Fri, 26 Sep 2025 12:06:39 -0400 Subject: [PATCH] Enhance CMake configuration for UI tests and SDL2 linking - Added support for UI tests in the CMake configuration by introducing the YAZE_ENABLE_UI_TESTS option, ensuring proper linking with the ImGuiTestEngine if available. - Updated SDL2 linking in test CMakeLists to use variable targets for improved flexibility and compatibility across platforms. - Modified sprite_position_test to check for ROM file existence using std::ifstream for better error handling. --- .github/workflows/ci.yml | 5 +++-- src/app/app.cmake | 12 ++++++++---- test/CMakeLists.txt | 4 ++-- test/zelda3/sprite_position_test.cc | 4 +++- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 06bd2ef1..ffca05ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -167,6 +167,7 @@ jobs: -DYAZE_MINIMAL_BUILD=ON \ -DYAZE_ENABLE_ROM_TESTS=OFF \ -DYAZE_ENABLE_EXPERIMENTAL_TESTS=OFF \ + -DYAZE_ENABLE_UI_TESTS=OFF \ -Wno-dev \ -GNinja @@ -174,13 +175,13 @@ jobs: if: runner.os == 'Windows' && env.BUILD_TYPE != 'RelWithDebInfo' shell: cmd run: | - cmake -B ${{ github.workspace }}/build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=${{ matrix.vcpkg_triplet }} -DCMAKE_POLICY_VERSION_MINIMUM=3.16 -DYAZE_MINIMAL_BUILD=ON -DYAZE_ENABLE_ROM_TESTS=OFF -DYAZE_ENABLE_EXPERIMENTAL_TESTS=OFF -Wno-dev -G "${{ matrix.cmake_generator }}" -A ${{ matrix.cmake_generator_platform }} + cmake -B ${{ github.workspace }}/build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=${{ matrix.vcpkg_triplet }} -DCMAKE_POLICY_VERSION_MINIMUM=3.16 -DYAZE_MINIMAL_BUILD=ON -DYAZE_ENABLE_ROM_TESTS=OFF -DYAZE_ENABLE_EXPERIMENTAL_TESTS=OFF -DYAZE_ENABLE_UI_TESTS=OFF -Wno-dev -G "${{ matrix.cmake_generator }}" -A ${{ matrix.cmake_generator_platform }} - name: Configure CMake (Windows minimal build) if: runner.os == 'Windows' && env.BUILD_TYPE == 'RelWithDebInfo' shell: cmd run: | - cmake -B ${{ github.workspace }}/build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCMAKE_POLICY_VERSION_MINIMUM=3.16 -DYAZE_MINIMAL_BUILD=ON -DYAZE_ENABLE_ROM_TESTS=OFF -DYAZE_ENABLE_EXPERIMENTAL_TESTS=OFF -Wno-dev -G "${{ matrix.cmake_generator }}" -A ${{ matrix.cmake_generator_platform }} + cmake -B ${{ github.workspace }}/build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCMAKE_POLICY_VERSION_MINIMUM=3.16 -DYAZE_MINIMAL_BUILD=ON -DYAZE_ENABLE_ROM_TESTS=OFF -DYAZE_ENABLE_EXPERIMENTAL_TESTS=OFF -DYAZE_ENABLE_UI_TESTS=OFF -Wno-dev -G "${{ matrix.cmake_generator }}" -A ${{ matrix.cmake_generator_platform }} # Build - name: Build diff --git a/src/app/app.cmake b/src/app/app.cmake index 8d989b34..95d3af4c 100644 --- a/src/app/app.cmake +++ b/src/app/app.cmake @@ -90,10 +90,14 @@ target_link_libraries( ) # Conditionally link ImGui Test Engine -if(YAZE_ENABLE_UI_TESTS AND TARGET ImGuiTestEngine) - target_include_directories(yaze PUBLIC ${CMAKE_SOURCE_DIR}/src/lib/imgui_test_engine) - target_link_libraries(yaze PUBLIC ${IMGUI_TEST_ENGINE_TARGET}) - target_compile_definitions(yaze PRIVATE YAZE_ENABLE_IMGUI_TEST_ENGINE=1) +if(YAZE_ENABLE_UI_TESTS) + if(TARGET ImGuiTestEngine) + target_include_directories(yaze PUBLIC ${CMAKE_SOURCE_DIR}/src/lib/imgui_test_engine) + target_link_libraries(yaze PUBLIC ImGuiTestEngine) + target_compile_definitions(yaze PRIVATE YAZE_ENABLE_IMGUI_TEST_ENGINE=1) + else() + target_compile_definitions(yaze PRIVATE YAZE_ENABLE_IMGUI_TEST_ENGINE=0) + endif() else() target_compile_definitions(yaze PRIVATE YAZE_ENABLE_IMGUI_TEST_ENGINE=0) endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7577937a..287862cc 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -72,7 +72,7 @@ target_include_directories( target_link_libraries( extract_vanilla_values - SDL2::SDL2 + ${SDL_TARGETS} asar-static ${ABSL_TARGETS} ${PNG_LIBRARIES} @@ -97,7 +97,7 @@ target_include_directories( target_link_libraries( yaze_test - SDL2::SDL2 + ${SDL_TARGETS} asar-static ${ABSL_TARGETS} ${PNG_LIBRARIES} diff --git a/test/zelda3/sprite_position_test.cc b/test/zelda3/sprite_position_test.cc index c7e72626..7eef003d 100644 --- a/test/zelda3/sprite_position_test.cc +++ b/test/zelda3/sprite_position_test.cc @@ -2,6 +2,7 @@ #include #include #include +#include #include "app/rom.h" #include "app/zelda3/overworld/overworld.h" @@ -18,7 +19,8 @@ protected: std::string rom_path = "bin/zelda3.sfc"; // Check if ROM exists in build directory - if (std::filesystem::exists(rom_path)) { + std::ifstream rom_file(rom_path); + if (rom_file.good()) { ASSERT_TRUE(rom_->LoadFromFile(rom_path).ok()) << "Failed to load ROM from " << rom_path; } else { // Skip test if ROM not found