Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Cmock, "fewer times than expected", can't get it to work...

115 views
Skip to first unread message

IJsbrand Wijnands

unread,
May 7, 2024, 11:46:58 AM5/7/24
to ThrowTheSwitch Forums
Hey folks,

I'm using 'ExpectAndReturn' for testing if functions are called and with the right arguments. This works great if the functions are called.

However, I've noticed that it doesn't work testing against these functions if they are NOT called. So if I define two:

some_function_ExpectAndReturn(call-1);
some_function_ExpectAndReturn(call-2);

If "some_function()" is only called once, and the test ends,  I would expect the test to fail and see the message "fewer times than expected", but I don't. I'm not using any Ignore calls.

I also tried to see if "enforce_strict_ordering" helps, but it doesn't. There must be something trivial I'm missing.

See below my .yaml file. I pulled Cmock  from git so I assume it is latest and greatest.

Any suggestions or pointers what I'm missing?

Thx,

Ice.

:cmock:
        :treat_externs: :include
        :when_ptr:      :compare_ptr
        :enforce_strict_ordering: 1
        :plugins:
          - :ignore
          - :ignore_arg
          - :expect_any_args
          - :return_thru_ptr
          - :callback
        :ignore:        :args_only

Mark Vander Voord

unread,
May 7, 2024, 11:59:35 AM5/7/24
to throwth...@googlegroups.com
I don't believe you mentioned how you're running the tests themselves? Are you using Ceedling? Rolling your own build system?

If you're running your own, are you calling the _Verify function for each of your mocks at the end of each test?

Mark

--
You received this message because you are subscribed to the Google Groups "ThrowTheSwitch Forums" group.
To unsubscribe from this group and stop receiving emails from it, send an email to throwtheswitc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/throwtheswitch/e03256f5-e677-40df-88c0-b0b833eb9f02n%40googlegroups.com.

IJsbrand Wijnands

unread,
May 7, 2024, 1:28:36 PM5/7/24
to throwth...@googlegroups.com
Thanks Mark for the response.

We’re running our own as this is part of a bigger build system with its own Makefile structure. I have tried to make it work with Ceedling initially, but I had run into too many Make challenges :)

I’m not calling any _Verify functions, do you have an example how that works?

Thx!

Ice.
> To view this discussion on the web visit https://groups.google.com/d/msgid/throwtheswitch/CAAu8-XGk0eMCdkPMAup5-Es%3D_0K%2BnXUpDv1ypNc6DS95qNJhyw%40mail.gmail.com.

IJsbrand Wijnands

unread,
May 7, 2024, 1:58:16 PM5/7/24
to throwth...@googlegroups.com
Ok, I see that Cmock is creating _Verify functions for each file that is mocked.

Just tried calling it for the file I was using, magic, it works now :-)

Thanks for your help Mark!

Ice.
> To view this discussion on the web visit https://groups.google.com/d/msgid/throwtheswitch/CEEE2F37-CCC3-4B8D-947A-68260B17918A%40wijnands.com.

Mark Vander Voord

unread,
May 7, 2024, 2:09:53 PM5/7/24
to throwth...@googlegroups.com
No problem!

If you don't mind a little Ruby, there are automatic scripts for generating the test runner (which has the bonus of having you never forget calls like this (or forget to add tests).

Otherwise, just keep adding the verify!  :)

Mark

Reply all
Reply to author
Forward
0 new messages