feat: Add Unittest example
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
set(MOCK_GEN_DIR "${CMAKE_CURRENT_BINARY_DIR}/mocks")
|
||||
file(MAKE_DIRECTORY "${MOCK_GEN_DIR}")
|
||||
|
||||
function(cmock_generate_mock target header)
|
||||
cmake_parse_arguments(ARG "" "" "CONFIG" ${ARGN})
|
||||
if (NOT RUBY_EXECUTABLE)
|
||||
message(FATAL_ERROR "Ruby is required for CMock generation")
|
||||
endif()
|
||||
get_filename_component(name "${header}" NAME_WE)
|
||||
get_filename_component(header_dir "${header}" DIRECTORY)
|
||||
set(mock_src "${MOCK_GEN_DIR}/Mock${name}.c")
|
||||
set(mock_hdr "${MOCK_GEN_DIR}/Mock${name}.h")
|
||||
if (ARG_CONFIG)
|
||||
set(CMOCK_CONFIG_FLAG "-o${ARG_CONFIG}")
|
||||
set(CMOCK_CONFIG_DEPENDS "${ARG_CONFIG}")
|
||||
endif()
|
||||
add_custom_command(
|
||||
OUTPUT "${mock_src}" "${mock_hdr}"
|
||||
COMMAND "${RUBY_EXECUTABLE}" "${CMOCK_SCRIPT}"
|
||||
${CMOCK_CONFIG_FLAG}
|
||||
"--mock_path=${MOCK_GEN_DIR}"
|
||||
"${header}"
|
||||
DEPENDS "${header}" ${CMOCK_CONFIG_DEPENDS}
|
||||
COMMENT "CMock: generating Mock${name}"
|
||||
VERBATIM
|
||||
)
|
||||
target_sources("${target}" PRIVATE "${mock_src}")
|
||||
target_include_directories("${target}" PRIVATE "${MOCK_GEN_DIR}" "${header_dir}")
|
||||
endfunction()
|
||||
|
||||
set(TEST_TARGETS "")
|
||||
|
||||
find_package(asio REQUIRED)
|
||||
|
||||
add_executable(test_example test_example.cpp)
|
||||
target_include_directories(test_example PRIVATE "${CMAKE_SOURCE_DIR}")
|
||||
target_link_libraries(test_example PRIVATE Unity::Unity)
|
||||
target_compile_features(test_example PRIVATE cxx_std_23)
|
||||
add_test(NAME test_example COMMAND test_example)
|
||||
list(APPEND TEST_TARGETS test_example)
|
||||
|
||||
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}
|
||||
)
|
||||
@@ -0,0 +1,14 @@
|
||||
#include "unity.h"
|
||||
|
||||
void setUp() {}
|
||||
void tearDown() {}
|
||||
|
||||
void test_example() {
|
||||
TEST_ASSERT_TRUE(true);
|
||||
}
|
||||
|
||||
auto main() -> int {
|
||||
UNITY_BEGIN();
|
||||
RUN_TEST(test_example);
|
||||
return UNITY_END();
|
||||
}
|
||||
Reference in New Issue
Block a user