ThrowTheSwitch / CMock

CMock - Mock/stub generator for C
http://throwtheswitch.org
MIT License
684 stars 276 forks source link

project.yml file not considered while generating mocks using cmake file #449

Closed NivethaSukumar closed 1 year ago

NivethaSukumar commented 1 year ago

CMakeLists.txt

...
foreach(header ${HEADERS_TO_MOCK})
  get_filename_component(base ${header} NAME_WE)
  set(mock ${MOCK_DIR}/mock_${base}.c)
  add_custom_command(OUTPUT ${mock}
    COMMAND ruby ${cmock_SOURCE_DIR}/lib/cmock.rb --config=${CMAKE_CURRENT_SOURCE_DIR}/project.yml --mock_prefix=mock_ --mock_path=${MOCK_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${header}
    DEPENDS ${header}
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    COMMENT "Generating mock for ${base}"
  )
  list(APPEND MOCKS ${mock})
endforeach()
...

project.yml file is

:cmock:
  :when_ptr: :compare
  :when_no_prototype: :warn
  :enforce_strict_ordering: false
  :plugins:
    - :ignore
    - :ignore_arg
    - :expect_any_args
    - :callback
    - :return_thru_ptr
  :treat_as:
    uint8_t: HEX8
    uint16_t: HEX16
    uint32_t: HEX32

I do not get any error however some of the mock functions are not generated using plugins described.

mvandervoord commented 1 year ago

Is there a project.yml in CMAKE_CURRENT_SOURCE_DIR ? It seems like you might be travelling multiple source dirs in this? Which has the project.yml file?

NivethaSukumar commented 1 year ago

Yes, I have fixed it and it seems to be working fine with the project.yml file.

# Generate a command to create each mock.
foreach(header ${HEADERS_TO_MOCK})
  get_filename_component(base ${header} NAME_WE)
  set(mock ${MOCK_DIR}/mock_${base}.c)
  add_custom_command(OUTPUT ${mock}
    COMMAND ruby ${cmock_SOURCE_DIR}/lib/cmock.rb -o${CMAKE_CURRENT_SOURCE_DIR}/project.yml  --mock_path=${MOCK_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${header}
    DEPENDS ${header}
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    COMMENT "Generating mock for ${base}"
  )
  list(APPEND MOCKS ${mock})
endforeach()

Thanks!

mvandervoord commented 1 year ago

Glad to hear it! Best of luck!