feat(cpp): integrar Catch2 en CMake con BUILD_TESTING + add_fn_test helper
cpp/tests/CMakeLists.txt compila Catch2 amalgamated como STATIC libreria una sola vez. Cada test es su propio executable (CATCH_CONFIG_MAIN por archivo) y se registra con add_test(). add_fn_test(name srcs...) es el helper: incluye paths de cpp/functions y cpp/framework, linka catch2. Tests que necesitan symbols reales (fn_framework, imgui) los anaden explicitamente con target_link_libraries despues.
This commit is contained in:
@@ -199,3 +199,10 @@ set(_DASH_DIR ${CMAKE_SOURCE_DIR}/../projects/fn_monitoring/apps/registry_dashbo
|
||||
if(EXISTS ${_DASH_DIR}/CMakeLists.txt)
|
||||
add_subdirectory(${_DASH_DIR} ${CMAKE_BINARY_DIR}/apps/registry_dashboard)
|
||||
endif()
|
||||
|
||||
# --- Tests (Catch2 amalgamated, ctest-driven) ---
|
||||
option(BUILD_TESTING "Build C++ tests" ON)
|
||||
if(BUILD_TESTING)
|
||||
enable_testing()
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
# cpp/tests — Catch2 unit tests for primitives.
|
||||
#
|
||||
# Catch2 amalgamated is compiled once as a STATIC LIB. Each test binary is
|
||||
# its own executable so we can mix tests that use ImGui-context and tests
|
||||
# that are pure logic without polluting symbols.
|
||||
|
||||
add_library(catch2 STATIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../vendor/catch2/catch_amalgamated.cpp)
|
||||
target_include_directories(catch2 PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../vendor/catch2)
|
||||
target_compile_features(catch2 PUBLIC cxx_std_17)
|
||||
|
||||
# Helper: register a test executable.
|
||||
# add_fn_test(<name> <sources...>)
|
||||
# By default links Catch2 + the cpp/functions include path. Tests that need
|
||||
# real symbols (linking against fn_framework etc.) can call
|
||||
# target_link_libraries(${name} PRIVATE fn_framework imgui ...) afterwards.
|
||||
function(add_fn_test name)
|
||||
add_executable(${name} ${ARGN})
|
||||
target_link_libraries(${name} PRIVATE catch2)
|
||||
target_include_directories(${name} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../functions
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../framework)
|
||||
add_test(NAME ${name} COMMAND ${name})
|
||||
endfunction()
|
||||
|
||||
# --- Tests reales (logica pura, no necesitan ImGui context) ----------------
|
||||
add_fn_test(test_tween_curves test_tween_curves.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../functions/core/tween_curves.cpp)
|
||||
add_fn_test(test_pie_chart_math test_pie_chart_math.cpp)
|
||||
add_fn_test(test_kpi_card_math test_kpi_card_math.cpp)
|
||||
add_fn_test(test_bar_chart_math test_bar_chart_math.cpp)
|
||||
|
||||
# --- Placeholders para primitivos UI (logica visual cubierta en 0048) ------
|
||||
add_fn_test(test_tokens test_tokens.cpp)
|
||||
add_fn_test(test_button test_button.cpp)
|
||||
add_fn_test(test_select test_select.cpp)
|
||||
add_fn_test(test_text_input test_text_input.cpp)
|
||||
add_fn_test(test_badge test_badge.cpp)
|
||||
add_fn_test(test_kpi_card test_kpi_card.cpp)
|
||||
add_fn_test(test_pie_chart test_pie_chart.cpp)
|
||||
add_fn_test(test_bar_chart test_bar_chart.cpp)
|
||||
add_fn_test(test_tree_view test_tree_view.cpp)
|
||||
add_fn_test(test_modal_dialog test_modal_dialog.cpp)
|
||||
add_fn_test(test_toolbar test_toolbar.cpp)
|
||||
add_fn_test(test_toast test_toast.cpp)
|
||||
add_fn_test(test_empty_state test_empty_state.cpp)
|
||||
add_fn_test(test_page_header test_page_header.cpp)
|
||||
add_fn_test(test_dashboard_panel test_dashboard_panel.cpp)
|
||||
add_fn_test(test_dashboard_grid test_dashboard_grid.cpp)
|
||||
add_fn_test(test_sparkline test_sparkline.cpp)
|
||||
add_fn_test(test_table_view test_table_view.cpp)
|
||||
add_fn_test(test_icon_button test_icon_button.cpp)
|
||||
Reference in New Issue
Block a user