From e0b71682973a6c3996a0032ae6b2c7ca4b34b9a5 Mon Sep 17 00:00:00 2001 From: Florian OMNES Date: Thu, 19 Dec 2024 16:30:29 +0100 Subject: [PATCH] Add and use add_boost_test CMake helper function --- .../binding_constraints/CMakeLists.txt | 41 +++++----------- .../end-to-end/simple_study/CMakeLists.txt | 47 +++++-------------- src/tests/macros.cmake | 14 ++++++ src/tests/src/api_internal/CMakeLists.txt | 34 ++++---------- .../antares/antlr4-interface/CMakeLists.txt | 23 +++------ 5 files changed, 54 insertions(+), 105 deletions(-) create mode 100644 src/tests/macros.cmake diff --git a/src/tests/end-to-end/binding_constraints/CMakeLists.txt b/src/tests/end-to-end/binding_constraints/CMakeLists.txt index 72e2e46f62..5b73d5fb61 100644 --- a/src/tests/end-to-end/binding_constraints/CMakeLists.txt +++ b/src/tests/end-to-end/binding_constraints/CMakeLists.txt @@ -1,30 +1,11 @@ -find_package(Boost COMPONENTS unit_test_framework REQUIRED) -enable_testing() - -#bigobj support needed for windows compilation -if(MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") -endif(MSVC) - -add_executable(tests-binding_constraints - test_binding_constraints.cpp - ) - -target_link_libraries(tests-binding_constraints - PRIVATE - Boost::unit_test_framework - model_antares - antares-solver-simulation - antares-solver-hydro - antares-solver-ts-generator - Antares::tests::in-memory-study - ) - -target_include_directories(tests-binding_constraints - PRIVATE - ${CMAKE_SOURCE_DIR}/solver - ) - -add_test(NAME end-to-end-binding_constraints COMMAND tests-binding_constraints) -set_property(TEST end-to-end-binding_constraints PROPERTY LABELS end-to-end) -set_target_properties(tests-binding_constraints PROPERTIES FOLDER Unit-tests/end_to_end) +include(${CMAKE_SOURCE_DIR}/tests/macros.cmake) + +add_boost_test(tests-binding_constraints + SRC test_binding_constraints.cpp + LIBS + Boost::unit_test_framework + model_antares + antares-solver-simulation + antares-solver-hydro + antares-solver-ts-generator + Antares::tests::in-memory-study) diff --git a/src/tests/end-to-end/simple_study/CMakeLists.txt b/src/tests/end-to-end/simple_study/CMakeLists.txt index cc5c93b410..1ab2e87c1e 100644 --- a/src/tests/end-to-end/simple_study/CMakeLists.txt +++ b/src/tests/end-to-end/simple_study/CMakeLists.txt @@ -1,35 +1,12 @@ -find_package(Boost COMPONENTS unit_test_framework REQUIRED) -enable_testing() - -#bigobj support needed for windows compilation -if(MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") -endif(MSVC) - -add_executable(tests-simple-study - simple-study.cpp -) - -target_link_libraries(tests-simple-study - PRIVATE - antares-solver-hydro - antares-solver-variable - antares-solver-simulation - antares-solver-ts-generator - model_antares - ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} - Antares::tests::in-memory-study -) - -target_include_directories(tests-simple-study - PRIVATE - ${CMAKE_SOURCE_DIR}/solver -) - -add_test(NAME end-to-end-simple-study COMMAND tests-simple-study) -set_property(TEST end-to-end-simple-study PROPERTY LABELS end-to-end) -set_target_properties(tests-simple-study PROPERTIES FOLDER Unit-tests/end_to_end) - -# Storing tests-simple-study under the folder Unit-tests in the IDE - -#---------------------------------------------------------- +include(${CMAKE_SOURCE_DIR}/tests/macros.cmake) + +add_boost_test(tests-simple-study + SRC simple-study.cpp + LIBS + antares-solver-hydro + antares-solver-variable + antares-solver-simulation + antares-solver-ts-generator + model_antares + ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} + Antares::tests::in-memory-study) diff --git a/src/tests/macros.cmake b/src/tests/macros.cmake new file mode 100644 index 0000000000..efa2305245 --- /dev/null +++ b/src/tests/macros.cmake @@ -0,0 +1,14 @@ +function(add_boost_test) + set(options "") + set(oneValueArgs) + set(multiValueArgs SRC LIBS) + cmake_parse_arguments(PARSE_ARGV 0 arg + "${options}" "${oneValueArgs}" "${multiValueArgs}") + # Bypass cmake_parse_arguments for the 1st argument + set(TEST_NAME ${ARGV0}) + add_executable(${TEST_NAME} ${arg_SRC}) + # All tests use boost + target_link_libraries(${TEST_NAME} PRIVATE ${arg_LIBS} Boost::unit_test_framework) + add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME}) + set_property(TEST ${TEST_NAME} PROPERTY LABELS unit) +endfunction() diff --git a/src/tests/src/api_internal/CMakeLists.txt b/src/tests/src/api_internal/CMakeLists.txt index 1c972cd4c6..47152fdf9f 100644 --- a/src/tests/src/api_internal/CMakeLists.txt +++ b/src/tests/src/api_internal/CMakeLists.txt @@ -1,28 +1,14 @@ -set(EXECUTABLE_NAME test-api) -add_executable(${EXECUTABLE_NAME}) +include(${CMAKE_SOURCE_DIR}/tests/macros.cmake) -target_sources(${EXECUTABLE_NAME} - PRIVATE - test_api.cpp -) +add_boost_test(test-api + SRC test_api.cpp + LIBS + Boost::unit_test_framework + Antares::solver_api + Antares::tests::in-memory-study + test_utils_unit) -target_link_libraries(${EXECUTABLE_NAME} - PRIVATE - Boost::unit_test_framework - Antares::solver_api - Antares::tests::in-memory-study - test_utils_unit -) - -target_include_directories(${EXECUTABLE_NAME} +target_include_directories(test-api PRIVATE #Allow to use the private headers - $ -) - -# Storing tests-ts-numbers under the folder Unit-tests in the IDE -set_target_properties(${EXECUTABLE_NAME} PROPERTIES FOLDER Unit-tests) - -add_test(NAME test-api COMMAND ${EXECUTABLE_NAME}) - -set_property(TEST test-api PROPERTY LABELS unit) + $) diff --git a/src/tests/src/libs/antares/antlr4-interface/CMakeLists.txt b/src/tests/src/libs/antares/antlr4-interface/CMakeLists.txt index f74e12981c..bef081975f 100644 --- a/src/tests/src/libs/antares/antlr4-interface/CMakeLists.txt +++ b/src/tests/src/libs/antares/antlr4-interface/CMakeLists.txt @@ -1,20 +1,11 @@ +include(${CMAKE_SOURCE_DIR}/tests/macros.cmake) find_package(antlr4-runtime CONFIG REQUIRED) -Set(SRCS test_antlr_interface.cpp -) +add_boost_test(antlr-interface-test + SRC test_antlr_interface.cpp + LIBS + antlr-interface) -set(execname "antlr-interface-test") -add_executable(${execname} ${SRCS}) -target_link_libraries(${execname} - PRIVATE - antlr-interface - Boost::unit_test_framework - ) - - -target_include_directories(${execname} +target_include_directories(antlr-interface-test PRIVATE - ${ANTLR4_INCLUDE_DIR}) -add_test(NAME antlr-interface COMMAND ${execname}) - -set_tests_properties(antlr-interface PROPERTIES LABELS unit) + ${ANTLR4_INCLUDE_DIR})