API inconsistency when ignoring a mock.
Hi all, First of all, thank you for delivering such an amazing framework. I've been enjoying using CMocka for a while now.
Now, to the actual "issue". Consider the following example:
int foo(int arg1, int arg2) {
function_called();
check_expected(arg1);
check_expected(arg2);
return mock_type(int);
}
Here I'm trying to create a complete `foo()` mock. Let's say I want to use it:
void bar()
{
foo(1, 2);
}
static void test_bar(void **state)
{
(void)state;
expect_function_call(foo);
expect_value(foo, arg1, 1);
expect_value(foo, arg2, 2);
will_return(foo, 0);
bar();
}
int main(int argc, char **argv)
{
(void)argc;
(void)argv;
const struct CMUnitTest tests[] = { cmocka_unit_test(test_bar) };
return cmocka_run_group_tests_name("example", tests, NULL, NULL);
}
So far so good. However, let's say that I want to ignore the foo() mock. CMocka API provides a set of functions/macros to do that. Therefore I can do something like:
static void test_bar_ignore_foo(void **state)
{
ignore_function_calls(foo);
will_return_maybe(foo, 0);
expect_any(foo, arg1);
expect_any(foo, arg2);
bar();
}
However, what if bar() calls foo() more than once? ignore_function_calls() and will_return_maybe() handle this situation just perfect. However, I will have to add expect_any() exactly a number of times foo() will be called, which means that I'm not really ignoring this mock.
Therefore I have 2 questions:
- Is there a way (API) to achieve what I'm asking for?
- If there's no such API do you have plans adding something like expect_maybe()? Do you think it's a good idea? I'd be happy to contribute.