Skip to content

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

Description

@mchernosky

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions