feat: add Unity color and check target
Enable UNITY_OUTPUT_COLOR and UNITY_INCLUDE_PRINT_FORMATTED via compile definitions on the unity target so colors propagate to all test suites automatically. Add a 'check' custom target that builds all suites and runs CTest with --output-on-failure and USES_TERMINAL, keeping ANSI colors alive through Ninja's buffering.
This commit is contained in:
@@ -28,12 +28,15 @@ function(cmock_generate_mock target header)
|
||||
target_include_directories("${target}" PRIVATE "${MOCK_GEN_DIR}" "${header_dir}")
|
||||
endfunction()
|
||||
|
||||
set(TEST_TARGETS "")
|
||||
|
||||
# str tests — pure functions, no mock needed
|
||||
add_executable(test_str test_str.c)
|
||||
target_include_directories(test_str PRIVATE "${CMAKE_SOURCE_DIR}")
|
||||
target_link_libraries(test_str PRIVATE ctdd_str Unity::Unity)
|
||||
target_compile_features(test_str PRIVATE c_std_23)
|
||||
add_test(NAME test_str COMMAND test_str)
|
||||
list(APPEND TEST_TARGETS test_str)
|
||||
|
||||
# report tests — mocks logger.h so log_info calls are intercepted
|
||||
add_executable(test_report test_report.c)
|
||||
@@ -42,6 +45,7 @@ target_link_libraries(test_report PRIVATE ctdd_report Unity::Unity CMock::CMock)
|
||||
target_compile_features(test_report PRIVATE c_std_23)
|
||||
cmock_generate_mock(test_report "${CMAKE_SOURCE_DIR}/ctdd/logger.h")
|
||||
add_test(NAME test_report COMMAND test_report)
|
||||
list(APPEND TEST_TARGETS test_report)
|
||||
|
||||
# logger tests — mocks log_write.h so output calls are intercepted
|
||||
add_executable(test_logger test_logger.c)
|
||||
@@ -50,3 +54,16 @@ target_link_libraries(test_logger PRIVATE ctdd_logger Unity::Unity CMock::CMock)
|
||||
target_compile_features(test_logger PRIVATE c_std_23)
|
||||
cmock_generate_mock(test_logger "${CMAKE_SOURCE_DIR}/ctdd/log_write.h")
|
||||
add_test(NAME test_logger COMMAND test_logger)
|
||||
list(APPEND TEST_TARGETS test_logger)
|
||||
|
||||
# 'check' builds all suites and runs CTest with full Unity output.
|
||||
# USES_TERMINAL keeps ANSI colors alive through Ninja's output buffering.
|
||||
add_custom_target(check
|
||||
COMMAND ${CMAKE_CTEST_COMMAND}
|
||||
--test-dir "${CMAKE_BINARY_DIR}"
|
||||
--output-on-failure
|
||||
--progress
|
||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
|
||||
USES_TERMINAL
|
||||
DEPENDS ${TEST_TARGETS}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user