I'm working on a C project using Ceedling for unit testing. I have a setup where I include custom data types defined in Types.h
in my Main.c
file and then include other headers sequentially, assuming they can access those data types indirectly.
For example:
Main.c:
#include "Types.h"
#include "Functions.h"
Functions.h:
u8 sum(u8 x, u8 y);
test_main.c:
#include"main.h"
#include"mock_functions.h"
In this setup, u8
is defined in Types.h
. Normally, Functions.h
can use u8
without explicitly including Types.h
because Main.c
includes Types.h
first. However, Ceedling throws an error saying the type u8
is unknown.
Is there a way to configure Ceedling to handle this, or do I need to include Types.h
explicitly in Functions.h
?
Error:
Generating include list for functions.h... Creating mock for functions... error: unknown type name 'u8' u8 SUM(u8 x , u8 y);
Notes:
I understand this isn't a good practice, and including dependencies explicitly is generally better. I'm asking if there's a way to make Ceedling work without modifying the headers.
I'm using Ceedling version 0.31.1.
Any advice or explanation would be appreciated!
Ceedling cannot handle this automatically, this is a bad dependency problem.
You have several solutions here, but the best is to include "Types.h" directly into "Functions.h".
If you really cannot edit the sources for some reason, you can add "Types.h" to your ceedling yaml file under [:cmock][:includes], this option can be used to inject header files into the generated mocks, see documentation.