ElectronVector / fake_function_framework

A plug-in for Ceedling to use the Fake Function Framework (fff) for mocking instead of Cmock.
MIT License
36 stars 13 forks source link

A mismatch stub function is generated by fff from a function declaration with a const pointer return type #1

Closed mchernosky closed 7 years ago

mchernosky commented 7 years ago

I met a problem when using fff in ceedling. If a function with a const pointer retruned is used in my test, its stub function is generated as a non-const return one and the build stops.

Test 'test_foo.c'
-----------------
Creating mock for bar...
Creating mock: build/test/mocks/mock_bar.h
Compiling mock_bar.c...
In file included from build/test/mocks/mock_bar.c:2:0:
build/test/mocks/mock_bar.c:11:32: error: conflicting types for ‘bar_get_message’
 DEFINE_FAKE_VALUE_FUNC0(char*, bar_get_message);
                                ^
/home/wang/test/temp_sensor/vendor/ceedling/plugins/fake_function_framework/vendor/fff/fff.h:1415:21: note: in definition of macro ‘DEFINE_FAKE_VALUE_FUNC0’
         RETURN_TYPE FUNCNAME(){ \
                     ^
In file included from build/test/mocks/mock_bar.h:6:0,
                 from build/test/mocks/mock_bar.c:3:
src/bar.h:13:13: note: previous declaration of ‘bar_get_message’ was here
 const char *bar_get_message(void);
             ^
ERROR: Shell command failed.
> Shell executed command:
'gcc -I"test" -I"src" -I"src/subfolder" -I"/home/wang/test/temp_sensor/vendor/ceedling/vendor/unity/src" -I"/home/wang/test/temp_sensor/vendor/ceedling/vendor/cmock/src" -I"build/test/mocks" -I"/home/wang/test/temp_sensor/vendor/ceedling/plugins/fake_function_framework/vendor/fff" -I"/home/wang/test/temp_sensor/vendor/ceedling/plugins/fake_function_framework/src" -DTEST -DGNU_COMPILER -g -c "build/test/mocks/mock_bar.c" -o "build/test/out/mock_bar.o"'
> And exited with status: [1].

rake aborted!

I did some research on the code and found that making some changes as follows will clear the problem.

diff -r temp_sensor/vendor/ceedling/plugins/fake_function_framework/lib/fff_mock_generator.rb ...
93c93
<
---
>
121c121,122
<       return_type = function[:return][:type]
---
>       return_type = (function[:modifier].empty? ? '' : "#{function[:modifier]} ")
>       return_type += function[:return][:type]

I know it's only a temporary solution and have not done any other test.