From 97018755aaf25f0e1d0deaf5292e6c7f8397f680 Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Sat, 16 Sep 2023 12:46:28 +0200 Subject: [PATCH 1/2] Add support for building the tests with CMake * Requires a present bake repository in test/ --- CMakeLists.txt | 6 ++++ test/.gitignore | 1 + test/CMakeLists.txt | 79 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 test/.gitignore create mode 100644 test/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index c7b7477679..7ff2a3b89c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ project(flecs LANGUAGES C) option(FLECS_STATIC "Build static flecs lib" ON) option(FLECS_SHARED "Build shared flecs lib" ON) option(FLECS_PIC "Compile static flecs lib with position independent code (PIC)" ON) +option(FLECS_TESTS "Build flecs tests" OFF) include(cmake/target_default_compile_warnings.cmake) include(cmake/target_default_compile_options.cmake) @@ -69,6 +70,11 @@ if(FLECS_STATIC) target_compile_definitions(flecs_static PUBLIC flecs_STATIC) endif() +if(FLECS_TESTS) + enable_testing() + add_subdirectory(test) +endif() + message(STATUS "Targets: ${FLECS_TARGETS}") # define the install steps diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 0000000000..4cfc12ad8c --- /dev/null +++ b/test/.gitignore @@ -0,0 +1 @@ +bake/ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000000..528a103f8a --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,79 @@ +project(flecs_tests LANGUAGES C CXX) + +if(NOT BAKE_DIRECTORY) + set(BAKE_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/bake") +endif() + +if(NOT IS_DIRECTORY "${BAKE_DIRECTORY}") + message(FATAL_ERROR "The CMake tests require a bake repository " + "at '${BAKE_DIRECTORY}'.") +endif() + +macro(add_flecs_test DIRECTORY) + get_filename_component(TEST_NAME_WE ${DIRECTORY} NAME_WE) + + file( + GLOB_RECURSE TEST_SOURCES CONFIGURE_DEPENDS + LIST_DIRECTORIES false + "${DIRECTORY}/*.cpp" "${DIRECTORY}/*.c" "${DIRECTORY}/*.h") + + foreach(CURRENT_FLECS_TARGET IN LISTS FLECS_TARGETS) + set(TEST_NAME "test_${TEST_NAME_WE}_${CURRENT_FLECS_TARGET}") + set(CTEST_NAME "flecs_${TEST_NAME_WE}_test_${CURRENT_FLECS_TARGET}") + + message(STATUS "Adding test ${TEST_NAME}") + + add_executable("${TEST_NAME}" ${TEST_SOURCES}) + + target_link_libraries("${TEST_NAME}" PUBLIC bake_base + ${CURRENT_FLECS_TARGET}) + + if(IS_DIRECTORY "${DIRECTORY}/include") + target_include_directories(${TEST_NAME} PUBLIC "${DIRECTORY}/include") + endif() + + set_target_properties( + ${TEST_NAME} + PROPERTIES VS_DEBUGGER_COMMAND_ARGUMENTS "-j 1" + VS_DEBUGGER_ENVIRONMENT + "BAKE_TEST_INPLACE=1\nBAKE_VERBOSITY=OK") + + add_test(NAME ${CTEST_NAME} COMMAND $) + + endforeach() +endmacro() + +# Polyfill for bake +file( + GLOB_RECURSE BAKE_SOURCES CONFIGURE_DEPENDS + LIST_DIRECTORIES false + "${BAKE_DIRECTORY}/src/*.c" + "${BAKE_DIRECTORY}/src/*.h" + "${BAKE_DIRECTORY}/drivers/test/src/*.c" + "${BAKE_DIRECTORY}/drivers/test/src/*.h" + "${BAKE_DIRECTORY}/util/src/*.c" + "${BAKE_DIRECTORY}/util/src/*.h") + +if(WIN32) + list(FILTER BAKE_SOURCES EXCLUDE REGEX "src/posix") +else() + list(FILTER BAKE_SOURCES EXCLUDE REGEX "src/win") +endif() + +add_library(bake_base SHARED ${BAKE_SOURCES}) +target_include_directories( + bake_base PUBLIC "${BAKE_DIRECTORY}/include" "${BAKE_DIRECTORY}/util/include" + "${BAKE_DIRECTORY}/drivers/test/include") +target_compile_definitions( + bake_base + PUBLIC __BAKE__=1 + PRIVATE bake_test_EXPORTS=1 UT_IMPL=1) + +if(WIN32) + target_link_libraries(bake_base PUBLIC Dbghelp Shlwapi Ws2_32) +endif() + +add_flecs_test("${CMAKE_CURRENT_LIST_DIR}/addons") +add_flecs_test("${CMAKE_CURRENT_LIST_DIR}/api") +add_flecs_test("${CMAKE_CURRENT_LIST_DIR}/collections") +add_flecs_test("${CMAKE_CURRENT_LIST_DIR}/cpp_api") From 1610e0cbd159bba2e4dd55bd0789894195bd939e Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Thu, 21 Sep 2023 19:59:58 +0200 Subject: [PATCH 2/2] Run the cmake tests in the ci --- .github/workflows/ci.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 83329f81ab..ebbdbd9b18 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -807,3 +807,27 @@ jobs: - name: run tests run: | bake run test/cpp_api --cfg sanitize -- -j 8 + + test-cmake: + needs: [ build-linux ] + runs-on: ${{ matrix.os }} + timeout-minutes: 30 + strategy: + fail-fast: false + matrix: + os: [ ubuntu-latest ] + + steps: + - uses: actions/checkout@v3 + - name: clone bake + run: | + git clone https://github.com/SanderMertens/bake + + - name: build flecs & tests + run: | + cmake -DFLECS_TESTS=ON -DBAKE_DIRECTORY=bake + make -j 8 + + - name: run tests + run: | + ctest -C Debug --verbose