Compare commits
2 Commits
7fbc4a49c5
...
286c51b2e7
| Author | SHA1 | Date | |
|---|---|---|---|
| 286c51b2e7 | |||
| 4b501676b7 |
@@ -166,3 +166,27 @@ void test_something_logs(void) {
|
|||||||
The `_Expect` call records the expected argument. CMock verifies the
|
The `_Expect` call records the expected argument. CMock verifies the
|
||||||
actual argument matches at call time using string comparison, and
|
actual argument matches at call time using string comparison, and
|
||||||
`Mocklogger_Verify` confirms the expected number of calls were made.
|
`Mocklogger_Verify` confirms the expected number of calls were made.
|
||||||
|
|
||||||
|
## Configuring CMock
|
||||||
|
|
||||||
|
Pass a config file as the third argument to `cmock_generate_mock`:
|
||||||
|
|
||||||
|
```cmake
|
||||||
|
cmock_generate_mock(test_mymodule "${CMAKE_SOURCE_DIR}/ctdd/logger.h"
|
||||||
|
"cmock_config.yml")
|
||||||
|
```
|
||||||
|
|
||||||
|
The file is loaded by the CMock Ruby generator with `-o`. A typical
|
||||||
|
`tests/cmock_config.yml` enables plugins:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
:cmock:
|
||||||
|
:plugins:
|
||||||
|
- :ignore
|
||||||
|
- :ignore_arg
|
||||||
|
- :return_thru_ptr
|
||||||
|
```
|
||||||
|
|
||||||
|
Use `:ignore` to skip certain mocks, `:ignore_arg` to stop checking
|
||||||
|
particular parameters, or `:return_thru_ptr` to have CMock write
|
||||||
|
through pointer return values automatically.
|
||||||
|
|||||||
Vendored
+37
@@ -15,6 +15,11 @@
|
|||||||
# IS_IOS - TRUE if building for iOS
|
# IS_IOS - TRUE if building for iOS
|
||||||
# IS_ANDROID - TRUE if building for Android
|
# IS_ANDROID - TRUE if building for Android
|
||||||
# IS_EMSCRIPTEN - TRUE if building for WebAssembly via Emscripten
|
# IS_EMSCRIPTEN - TRUE if building for WebAssembly via Emscripten
|
||||||
|
#
|
||||||
|
# Architecture flags set:
|
||||||
|
# ARCH - Normalized architecture name (amd64, arm64, wasm, etc.)
|
||||||
|
# IS_AMD64 - TRUE if building for x86_64/amd64
|
||||||
|
# IS_ARM64 - TRUE if building for arm64/aarch64
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
@@ -62,3 +67,35 @@ elseif(UNIX)
|
|||||||
else()
|
else()
|
||||||
message(FATAL_ERROR "Unknown platform!")
|
message(FATAL_ERROR "Unknown platform!")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Architecture Detection
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
set(ARCH "")
|
||||||
|
set(IS_AMD64 FALSE)
|
||||||
|
set(IS_ARM64 FALSE)
|
||||||
|
|
||||||
|
if (IS_EMSCRIPTEN)
|
||||||
|
set(ARCH "wasm")
|
||||||
|
elseif(DEFINED CMAKE_OSX_ARCHITECTURES)
|
||||||
|
# Cross-compile on macOS (e.g. iOS simulator on Apple Silicon)
|
||||||
|
set(ARCH "${CMAKE_OSX_ARCHITECTURES}")
|
||||||
|
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64|^arm64|^ARM64")
|
||||||
|
set(ARCH "arm64")
|
||||||
|
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^x86_64|^AMD64|^x64")
|
||||||
|
set(ARCH "amd64")
|
||||||
|
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^armv[0-9]")
|
||||||
|
set(ARCH "arm")
|
||||||
|
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^i[3-6]86")
|
||||||
|
set(ARCH "x86")
|
||||||
|
else()
|
||||||
|
set(ARCH "${CMAKE_SYSTEM_PROCESSOR}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(ARCH STREQUAL "amd64")
|
||||||
|
set(IS_AMD64 TRUE)
|
||||||
|
elseif(ARCH STREQUAL "arm64")
|
||||||
|
set(IS_ARM64 TRUE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
message(STATUS "Architecture: ${ARCH}")
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ set(MOCK_GEN_DIR "${CMAKE_CURRENT_BINARY_DIR}/mocks")
|
|||||||
file(MAKE_DIRECTORY "${MOCK_GEN_DIR}")
|
file(MAKE_DIRECTORY "${MOCK_GEN_DIR}")
|
||||||
|
|
||||||
# Generate a CMock mock from a header and attach it to a target.
|
# Generate a CMock mock from a header and attach it to a target.
|
||||||
# Usage: cmock_generate_mock(<target> <absolute-path-to-header>)
|
# Usage: cmock_generate_mock(<target> <absolute-path-to-header> [config.yml])
|
||||||
# CMock names generated files Mock<Name>.h/.c (capital M, no separator)
|
# CMock names generated files Mock<Name>.h/.c (capital M, no separator)
|
||||||
|
# If a config file is given it is passed to the Ruby generator with `-o`.
|
||||||
function(cmock_generate_mock target header)
|
function(cmock_generate_mock target header)
|
||||||
|
cmake_parse_arguments(ARG "" "" "CONFIG" ${ARGN})
|
||||||
if (NOT RUBY_EXECUTABLE)
|
if (NOT RUBY_EXECUTABLE)
|
||||||
message(FATAL_ERROR "Ruby is required for CMock generation")
|
message(FATAL_ERROR "Ruby is required for CMock generation")
|
||||||
endif()
|
endif()
|
||||||
@@ -15,12 +17,17 @@ function(cmock_generate_mock target header)
|
|||||||
get_filename_component(header_dir "${header}" DIRECTORY)
|
get_filename_component(header_dir "${header}" DIRECTORY)
|
||||||
set(mock_src "${MOCK_GEN_DIR}/Mock${name}.c")
|
set(mock_src "${MOCK_GEN_DIR}/Mock${name}.c")
|
||||||
set(mock_hdr "${MOCK_GEN_DIR}/Mock${name}.h")
|
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(
|
add_custom_command(
|
||||||
OUTPUT "${mock_src}" "${mock_hdr}"
|
OUTPUT "${mock_src}" "${mock_hdr}"
|
||||||
COMMAND "${RUBY_EXECUTABLE}" "${CMOCK_SCRIPT}"
|
COMMAND "${RUBY_EXECUTABLE}" "${CMOCK_SCRIPT}"
|
||||||
|
${CMOCK_CONFIG_FLAG}
|
||||||
"--mock_path=${MOCK_GEN_DIR}"
|
"--mock_path=${MOCK_GEN_DIR}"
|
||||||
"${header}"
|
"${header}"
|
||||||
DEPENDS "${header}"
|
DEPENDS "${header}" ${CMOCK_CONFIG_DEPENDS}
|
||||||
COMMENT "CMock: generating Mock${name}"
|
COMMENT "CMock: generating Mock${name}"
|
||||||
VERBATIM
|
VERBATIM
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user