Skip to content

Using treat_inlines changes what gets mocked #513

@victor-sutardja-ai

Description

@victor-sutardja-ai

I'm having trouble mocking some 3rd-party code; and I've been able to reduce it to a small example.

The input header:

  1. Uses a macro function to declare a struct type, and
  2. Has a static inline function
#include "foo_type.h"
struct FOO_TYPE(bar) { int baz; };
static inline char b(void) { return 0; }

The default behavior excludes static inline functions, so there is nothing to mock, i.e. cmock can correctly determine that struct FOO_TYPE(bar) { int baz; }; is not a function prototype.

To create mocks for static inline functions, I pass --treat_inlines=:include, which generates a correctly-normalized header file:

#include "foo_type.h"
struct FOO_TYPE(bar) { int baz; };
char b(void);

And successfully mocks b, but now cmock also tries to mock the struct type declaration, resulting in invalid syntax, e.g.:

void FOO_TYPE_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, bar cmock_arg1, struct cmock_to_return);
                                          unknown type names ~~^             ~~^

This doesn't appear to have anything to do with the normalization of the original header file, since directly mocking the generated normalized header produces similar results (mocks b only when excluding inlines, but mocks b and FOO_TYPE when including inlines).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions