From 9039854d868ca690c5f4c76c8954bf8c5576c54b Mon Sep 17 00:00:00 2001 From: GauthierMalfilatre Date: Thu, 24 Sep 2026 00:06:53 +0200 Subject: [PATCH 1/2] [UP] Update CMakeLists to build test for project's root --- CMakeLists.txt | 7 +++++++ tests/CMakeLists.txt | 13 ++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ebd8f1a..f6e1b51 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,3 +51,10 @@ install(TARGETS kronknet-static kronknet-shared install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/kronknet DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) + +option(BUILD_TESTS "Build the unit tests (run them with ctest)" OFF) + +if(BUILD_TESTS) + enable_testing() + add_subdirectory(tests) +endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4ef675b..0cd2a5d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,5 +1,4 @@ -cmake_minimum_required(VERSION 3.20) -project(kronknet_tests LANGUAGES C) +# NOTE: Included from the root CMakeLists.txt with -DBUILD_TESTS=ON include(FetchContent) @@ -11,11 +10,6 @@ FetchContent_Declare( FetchContent_MakeAvailable(kronklab) -# NOTE: Build kronknet from this repository, not the installed one -if(NOT TARGET kronknet) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_BINARY_DIR}/kronknet) -endif() - file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/utils/*.c ${CMAKE_CURRENT_SOURCE_DIR}/network/*.c @@ -26,3 +20,8 @@ add_executable(kronknet_tests ${SOURCES}) target_include_directories(kronknet_tests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/) target_link_libraries(kronknet_tests PRIVATE kronklab kronknet) + +add_test(NAME kronknet_tests COMMAND kronknet_tests) + +# NOTE: kronklab has no per-test timeout, so a stuck test must not hang CI +set_tests_properties(kronknet_tests PROPERTIES TIMEOUT 120) From 57aa0c1ba007bd0fa5fadf717f89c33ab7a4004e Mon Sep 17 00:00:00 2001 From: GauthierMalfilatre Date: Thu, 24 Sep 2026 00:07:12 +0200 Subject: [PATCH 2/2] [FIX] Fix workflows to actually run tests --- .github/workflows/main.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 898be0c..e2a2538 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -97,11 +97,13 @@ jobs: image: epitechcontent/epitest-docker steps: - uses: actions/checkout@v4 - - name: Check compilation - timeout-minutes: 2 + - name: Build tests + timeout-minutes: 5 run: | - cmake -S . -B build + cmake -S . -B build -DBUILD_TESTS=ON cmake --build build --parallel - ctest --test-dir build --output-on-failure + - name: Run tests + timeout-minutes: 3 + run: ctest --test-dir build --output-on-failure - name: Cleaning run: rm -rf build