Skip to content

tests: Provide style definition to the C / C++ tests.#465

Merged
emilio merged 2 commits intomozilla:masterfrom
emilio:layout-test
Jan 26, 2020
Merged

tests: Provide style definition to the C / C++ tests.#465
emilio merged 2 commits intomozilla:masterfrom
emilio:layout-test

Conversation

@emilio
Copy link
Copy Markdown
Collaborator

@emilio emilio commented Jan 26, 2020

This will be useful to add static assertion to some tests like #463 wants to do.

For example, in the case of the test for #463, the test would need something
like:

trailer = """
#include <assert.h>

#if defined(CBINDGEN_STYLE_TAG) && !defined(__cplusplus)
static_assert(sizeof(struct P) == 4, "unexpected size for P");
#else
static_assert(sizeof(P) == 4, "unexpected size for P");
#endif
"""

As more of these tests are added it may be worth just adding a helper header
like this to avoid some duplication:

#include <assert.h>
#if defined(CBINDGEN_STYLE_TAG) && !defined(__cplusplus)
#define CBINDGEN_STRUCT(name) struct name
#else
#define CBINDGEN_STRUCT(name) name
#endif

And so on, so the previous configuration would become just:

trailer = """
#include "testing-helpers.h" // Or whatever
static_assert(sizeof(CBINDGEN_STRUCT(P)) == 4, "unexpected size for P");
"""

That may or may not be overkill to do as part of #463.

This will be useful to add static assertion to some tests like mozilla#463 wants to do.

For example, in the case of the test for mozilla#463, the test would need something
like:

    trailer = """
    #include <assert.h>

    #if defined(CBINDGEN_STYLE_TAG) && !defined(__cplusplus)
    static_assert(sizeof(struct P) == 4, "unexpected size for P");
    #else
    static_assert(sizeof(P) == 4, "unexpected size for P");
    #endif
    """

As more of these tests are added it may be worth just adding a helper header
like this to avoid some duplication:

    #include <assert.h>
    #if defined(CBINDGEN_STYLE_TAG) && !defined(__cplusplus)
    #define CBINDGEN_STRUCT(name) struct name
    #else
    #define CBINDGEN_STRUCT(name) name
    #endif

And so on, so the previous configuration would become just:

    trailer = """
    #include "testing-helpers.h" // Or whatever
    static_assert(sizeof(CBINDGEN_STRUCT(P)) == 4, "unexpected size for P");
    """

That may or may not be overkill to do as part of mozilla#463.
This allows to assert easily as described in the previous commit.
@emilio emilio merged commit 12248c2 into mozilla:master Jan 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant