FreeYourSoul / FSeam

Cpp header only library to manage compile time mock class generated via Python script
MIT License
86 stars 8 forks source link

Preprocessor disabled code-section leads to generated MockClass code #32

Open jenisys opened 4 years ago

jenisys commented 4 years ago

Describe the bug If the C++ ClassToMock header contains code-sections that are disabled by using the C preprocessor idiom #if 0 ... #endif, the disabled code-section causes generated ClassA::method1 code in FSeamMockData.hpp:

class ClassToMock
{
public:
   ...
#if 0
    // -- DISABLED CODE SECTION: NotImplementedYet / NotSupportedYet
    void method1(UnknownClass value);
#endif

WORK-AROUND: Use comments instead of preprocessor to disable the code-section (comment it out).

To Reproduce Described above. If the disabled code-section causes problems with FSeam, compile-time errors are caused.

Expected behavior Disabled code-section (especially with this simple-idiom that requires no knowledge of preprocessor-defines) should not lead to code in generated MockData.

FreeYourSoul commented 4 years ago

Code generation is based on the c++ header parser https://github.com/robotpy/robotpy-cppheaderparser.

It is unfortunately, a naive approach that may not give the code generator the appropriate informations to decide which preprocessor condition is true or not.

The graal of this code generator would be to use a libclang and actually not have a naive python parser but something working directly with the AST, I will update the documentation and try to think how we could solve this issue in a naive way.