Add mock Arduino for x86_64 host-side testing
Complete Arduino API mock (mock_arduino.h/cpp) enabling application code to compile and run on PC without hardware. Includes MockSerial, String class, GPIO/analog/timing/interrupt mocks with state tracking and test control API. - Arduino.h, Wire.h, SPI.h shims intercept includes in test builds - System test template (test_system.cpp) using SimHal - CMakeLists.txt builds mock_arduino as static lib, links both suites - Root test.sh/test.bat with --unit/--system/--clean/--verbose flags - test.bat auto-detects MSVC via vswhere + vcvarsall.bat - Doctor reports nuanced compiler status (on PATH vs installed) - Refresh pulls mock infrastructure into existing projects - 15 tests passing: 7 unit (MockHal) + 8 system (SimHal)
This commit is contained in:
@@ -30,7 +30,19 @@ include_directories(
|
||||
)
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# Unit tests (Google Mock)
|
||||
# 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
|
||||
@@ -38,6 +50,18 @@ add_executable(test_unit
|
||||
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
|
||||
)
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
@@ -45,3 +69,4 @@ target_link_libraries(test_unit
|
||||
# --------------------------------------------------------------------------
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(test_unit)
|
||||
gtest_discover_tests(test_system)
|
||||
|
||||
Reference in New Issue
Block a user