Closed jvieira88 closed 6 months ago
The function getBaseVal
has a return value, therefore it'll generate a getBaseVal_ExpectAndReturn()
instead of a getBaseVal_Expect
because if you're expecting it to get called, CMock also needs to know what it should return when the mock is called. :)
Thanks for the clarification! That makes sense, I just assumed that all the mock methods would be created. I confirm it's working now :)
Don't worry. This is often confusing for most people coming to CMock. I'm trying to think of a way to better prepare people for this behavior. It makes sense when it's brought up... but the "least surprising" behavior would be to still have an _Expect
option. The problem if we DID also provide an _Expect
function is that it would just return 0
because nothing was specified... and then people have a very hard time trying to figure out why their tests are failing.
Anyway, best of luck!
How about getting an Expect() function which would produce a compiler warning beside returning zero:
"Your function is expected to return a value, but you forgot to specify it using _ExpectAndReturn(). Returning 0 as default"
I like this idea a lot. Anything that helps people find their own bugs is a win in my book. We could probably even simplify it down to a single call in cmock.c and just wrap it in macros for each function being tested, so that we keep the overhead down. :)
I'm reopening this bug, because I think this is 100% worth doing.
Added the feature discussed above ❤️
Hi,
I'm using CMock with Ceedling for the first time. I'm just running a quick test to try out CMock but I'm not getting the same CMock methods (or signatures) as expected per the documentation. For example, the _Expect method seems to be missing.
Here's my system setup:
Here are some code files:
DumbExample.h
DumbExample.c
DumbBaseValue.h
DumbBaseValue.c
Generated mock_DumbBaseValue.h
test_DumbExample.c
Error message:
test/test_DumbExample.c:29:2: warning: implicit declaration of function 'getBaseVal_Expect'; did you mean 'getBaseVal_Stub'?
Any idea why this is happening? The
_Expect
method is not being generated in the mock file.