Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TW#28226] unity without cmock?? #2900

Closed
markfink opened this issue Dec 29, 2018 · 3 comments
Closed

[TW#28226] unity without cmock?? #2900

markfink opened this issue Dec 29, 2018 · 3 comments

Comments

@markfink
Copy link

@markfink markfink commented Dec 29, 2018

today I discovered that you have unity support but without cmock (which usually goes hand-in-hand).

Thank you,
Mark

----------------------------- Delete below -----------------------------

@markfink

This comment has been minimized.

Copy link
Author

@markfink markfink commented Dec 29, 2018

I managed to add CMock support using CMake (please take a look https://github.com/finklabs/esp32/tree/master/cmock_demo)

However it appears like there is sth. wrong with the CMake bassed build system. I could not add to COMPONENT_SRCS dynamically (in create_mock.cmake). I had to add the src by hand (very ugly). If you have an idea on how to fix that please share.

set(COMPONENT_SRCS "test_cmp_demo.c" "../include/mocks/mock_dep_demo.c")
# set(COMPONENT_SRCS "test_cmp_demo.c")  # TODO regretably this does not work :(
set(COMPONENT_ADD_INCLUDEDIRS "." "../include")

set(COMPONENT_REQUIRES unity cmock cmp_demo)

register_component()

get_filename_component(header_abs_path ../include/dep_demo.h REALPATH )
create_mock(mock_dep_demo ${header_abs_path})
@Alvin1Zhang Alvin1Zhang changed the title unity without cmock?? [TW#28226] unity without cmock?? Jan 2, 2019
@projectgus

This comment has been minimized.

Copy link
Member

@projectgus projectgus commented Jan 2, 2019

Hi @markfink,

That's right, we don't use CMock internally (yet). We added unity for testing ESP-IDF itself, and so far we've either tested everything on real hardware or written standalone tests to run on the host, rather than mocking out implementations on the device.

However it appears like there is sth. wrong with the CMake bassed build system. I could not add to COMPONENT_SRCS dynamically (in create_mock.cmake)

The COMPONENT_SRCS variable is used inside register_component(). If you move the call to create_mock to above register_component then it should be possible to add items to the COMPONENT_SRCS variable (using PARENT_SCOPE) from inside the create_mock() function.

A better approach (IMO) is to keep the existing function call order and call CMake's target_sources(${COMPONENT_TARGET} PRIVATE extra_srcs go_here) function to add more sources to the component target (which is created in CMake inside register_component()).

@markfink

This comment has been minimized.

Copy link
Author

@markfink markfink commented Jan 2, 2019

@projectgus works great! thank you for the advice. especially your insight into register_component() mechanics

@markfink markfink closed this Jan 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.