ThrowTheSwitch / CMock

CMock - Mock/stub generator for C
http://throwtheswitch.org
MIT License
684 stars 276 forks source link

Cmock cannot cope with macros in function declarations #429

Closed mattconway1984 closed 8 months ago

mattconway1984 commented 1 year ago

Take for example:

#if TEST_BUILD
#define INLINE
#else
#define INLINE extern inline
#endif

// silly inline function for demo
INLINE void Foo(char *x);
#if TEST_BUILD
; // Cmock cannot cope with inline functions unless you mess with cmock config which in turn breaks other stuff, so declare function (not inline)
#else
{
  *x++; // pointless statement for demo
}
#endif

Then guess what happens.....

void Foo_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, char *x, INLINE void cmock_to_return)

Why does Cmock not attempt to pre-process the file before mock generation?

mvandervoord commented 1 year ago

If you're using Ceedling, just enable preprocessing in the project file. If you're not, it's your responsibility to call the preprocessor before calling CMock. CMock just operates on whatever you give it. While someday we'd love to have it a fullblown C parser, it's not at this point... it just handles the majority of cases and leaves odd corner cases as tasks for the developer to figure out how to preprocess.