102 lines
3.3 KiB
Cheetah
102 lines
3.3 KiB
Cheetah
cmake_minimum_required(VERSION 3.14)
|
|
project({{PROJECT_NAME}}_tests LANGUAGES CXX)
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
# --------------------------------------------------------------------------
|
|
# Google Test (fetched automatically on first build)
|
|
# --------------------------------------------------------------------------
|
|
include(FetchContent)
|
|
FetchContent_Declare(
|
|
googletest
|
|
GIT_REPOSITORY https://github.com/google/googletest.git
|
|
GIT_TAG v1.14.0
|
|
)
|
|
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
|
FetchContent_MakeAvailable(googletest)
|
|
|
|
enable_testing()
|
|
|
|
# --------------------------------------------------------------------------
|
|
# Include paths -- same headers the Arduino sketch uses
|
|
# --------------------------------------------------------------------------
|
|
set(LIB_DIR ${CMAKE_SOURCE_DIR}/../lib)
|
|
|
|
include_directories(
|
|
${LIB_DIR}/hal
|
|
${LIB_DIR}/app
|
|
${CMAKE_SOURCE_DIR}/mocks
|
|
)
|
|
|
|
# Auto-discover driver libraries (added by: anvil add <driver>)
|
|
if(IS_DIRECTORY ${LIB_DIR}/drivers)
|
|
file(GLOB DRIVER_DIRS ${LIB_DIR}/drivers/*)
|
|
foreach(DRIVER_DIR ${DRIVER_DIRS})
|
|
if(IS_DIRECTORY ${DRIVER_DIR})
|
|
include_directories(${DRIVER_DIR})
|
|
endif()
|
|
endforeach()
|
|
endif()
|
|
|
|
# --------------------------------------------------------------------------
|
|
# Mock Arduino library -- provides Arduino API on x86_64
|
|
# --------------------------------------------------------------------------
|
|
add_library(mock_arduino STATIC
|
|
mocks/mock_arduino.cpp
|
|
)
|
|
target_include_directories(mock_arduino PUBLIC
|
|
${CMAKE_SOURCE_DIR}/mocks
|
|
${LIB_DIR}/hal
|
|
${LIB_DIR}/app
|
|
)
|
|
|
|
# --------------------------------------------------------------------------
|
|
# Unit tests (Google Mock -- verifies exact HAL call sequences)
|
|
# --------------------------------------------------------------------------
|
|
add_executable(test_unit
|
|
test_unit.cpp
|
|
)
|
|
target_link_libraries(test_unit
|
|
GTest::gtest_main
|
|
GTest::gmock
|
|
mock_arduino
|
|
)
|
|
|
|
# --------------------------------------------------------------------------
|
|
# System tests (SimHal -- exercises full application logic)
|
|
# --------------------------------------------------------------------------
|
|
add_executable(test_system
|
|
test_system.cpp
|
|
)
|
|
target_link_libraries(test_system
|
|
GTest::gtest_main
|
|
mock_arduino
|
|
)
|
|
|
|
# --------------------------------------------------------------------------
|
|
# Register with CTest
|
|
# --------------------------------------------------------------------------
|
|
include(GoogleTest)
|
|
gtest_discover_tests(test_unit)
|
|
gtest_discover_tests(test_system)
|
|
|
|
# --------------------------------------------------------------------------
|
|
# Driver tests (added automatically by: anvil add <driver>)
|
|
# --------------------------------------------------------------------------
|
|
file(GLOB DRIVER_TEST_SOURCES ${CMAKE_SOURCE_DIR}/test_*.cpp)
|
|
# Exclude test_unit.cpp and test_system.cpp (already handled above)
|
|
list(FILTER DRIVER_TEST_SOURCES EXCLUDE REGEX "test_unit\\.cpp$")
|
|
list(FILTER DRIVER_TEST_SOURCES EXCLUDE REGEX "test_system\\.cpp$")
|
|
|
|
foreach(TEST_SOURCE ${DRIVER_TEST_SOURCES})
|
|
get_filename_component(TEST_NAME ${TEST_SOURCE} NAME_WE)
|
|
add_executable(${TEST_NAME} ${TEST_SOURCE})
|
|
target_link_libraries(${TEST_NAME}
|
|
GTest::gtest_main
|
|
GTest::gmock
|
|
mock_arduino
|
|
)
|
|
gtest_discover_tests(${TEST_NAME})
|
|
endforeach()
|