Skip to content

Commit

Permalink
Make tests work with CTest (#1539)
Browse files Browse the repository at this point in the history
Adds option to disable non-free tests
  • Loading branch information
JL2210 authored Oct 15, 2024
1 parent a2ff653 commit e623aeb
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 12 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ jobs:
run: |
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=${{ matrix.cxx }} -DSANITIZERS=ON -DMORE_WARNINGS=ON
cmake --build build -j --verbose
cp build/src/rgb{asm,link,fix,gfx} .
sudo cmake --install build --verbose
cmake --install build --verbose --component "Test support programs"
- name: Package binaries
run: |
mkdir bins
Expand Down Expand Up @@ -175,7 +173,6 @@ jobs:
cmake -S . -B build -A ${{ matrix.platform }} -DCMAKE_INSTALL_PREFIX=install_dir -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release -j --verbose
cmake --install build --verbose --prefix install_dir
cmake --install build --verbose --component "Test support programs"
- name: Package binaries
shell: bash
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
CMakeCache.txt
CMakeFiles/
cmake_install.cmake
build/
callgrind.out.*
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# SPDX-License-Identifier: MIT

# 3.9 required for LTO checks
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
# 3.17 optional for CMAKE_CTEST_ARGUMENTS
cmake_minimum_required(VERSION 3.9..3.17 FATAL_ERROR)

project(rgbds
LANGUAGES CXX)

include(CTest)

# get real path of source and binary directories
get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH)
Expand Down Expand Up @@ -87,6 +90,8 @@ endif(GIT)
find_package(PkgConfig)
if(MSVC OR NOT PKG_CONFIG_FOUND)
# fallback to find_package
# cmake's FindPNG is very fragile; it breaks when multiple versions are installed
# this is most evident on macOS but can occur on Linux too
find_package(PNG REQUIRED)
else()
pkg_check_modules(LIBPNG REQUIRED libpng)
Expand All @@ -98,6 +103,7 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)

add_subdirectory(src)
set(CMAKE_CTEST_ARGUMENTS "--verbose")
add_subdirectory(test)

# By default, build in Release mode; Debug mode must be explicitly requested
Expand Down
7 changes: 4 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ foreach(PROG "asm" "fix" "gfx" "link")
${rgb${PROG}_src}
${common_src}
)
if(SUFFIX)
set_target_properties(rgb${PROG} PROPERTIES SUFFIX ${SUFFIX})
endif()
install(TARGETS rgb${PROG} RUNTIME DESTINATION bin)
# Required to run tests
set_target_properties(rgb${PROG} PROPERTIES
# hack for MSVC: no-op generator expression to stop generation of "per-configuration subdirectory"
RUNTIME_OUTPUT_DIRECTORY $<1:${CMAKE_SOURCE_DIR}>)
endforeach()

if(LIBPNG_FOUND) # pkg-config
Expand Down
20 changes: 15 additions & 5 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# SPDX-License-Identifier: MIT

OPTION(USE_NONFREE_TESTS "run tests that build nonfree codebases" ON)

if(NOT USE_NONFREE_TESTS)
set(ONLY_FREE "--only-free")
endif()

add_executable(randtilegen gfx/randtilegen.cpp)
add_executable(rgbgfx_test gfx/rgbgfx_test.cpp)
set_target_properties(randtilegen rgbgfx_test PROPERTIES
# hack for MSVC: no-op generator expression to stop generation of "per-configuration subdirectory"
RUNTIME_OUTPUT_DIRECTORY $<1:${CMAKE_CURRENT_SOURCE_DIR}/gfx>)

install(TARGETS randtilegen rgbgfx_test
DESTINATION ${rgbds_SOURCE_DIR}/test/gfx
COMPONENT "Test support programs"
EXCLUDE_FROM_ALL
)
configure_file(CTestCustom.cmake.in ${CMAKE_BINARY_DIR}/CTestCustom.cmake)

foreach(TARGET randtilegen rgbgfx_test)
if(LIBPNG_FOUND) # pkg-config
Expand All @@ -20,3 +25,8 @@ foreach(TARGET randtilegen rgbgfx_test)
target_link_libraries(${TARGET} PRIVATE ${PNG_LIBRARIES})
endif()
endforeach()

add_test(NAME all
COMMAND ./run-tests.sh ${ONLY_FREE}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
1 change: 1 addition & 0 deletions test/CTestCustom.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(CTEST_CUSTOM_PRE_TEST "bash -c 'cd @CMAKE_CURRENT_SOURCE_DIR@\; ./fetch-test-deps.sh @ONLY_FREE@'")

0 comments on commit e623aeb

Please sign in to comment.