1
0
mirror of https://github.com/ThrowTheSwitch/Unity.git synced 2026-01-28 10:44:26 +01:00

MISRA rule 19.10: parentheses around macro params

Added parentheses around all macro parameters to resolve MISRA 2004
rule 19.10, "in the definition of a function-like macro, each instance
of a parameter shall be enclosed in parenthesis" as tested with the
IAR EW for 8051 compiler, version 9.20.2.

The only questionable change is in "unity_fixture.h" where the nested
macro DECLARE_TEST_CASE in RUN_TEST_CASE prevents surrounding params
"group" and "name" with parentheses.
However, it appears that macro DECLARE_TEST_CASE isn't used elsewhere,
so I eliminated DECLARE_TEST_CASE and put its expansion directly in
RUN_TEST_CASE.  Now the following header files pass rule 19.10:
* unity.h
* unity_internals.h
* unity_fixture.h

For my own project, this change to the Unity test framework allows me
to include my unit test code to be tested against MISRA rules as well,
instead of just production code, to help enforce style and team
guidelines.
This commit is contained in:
Jeremy Hannon
2015-10-14 17:19:26 -05:00
parent 6621bc81c4
commit 1273112a05
3 changed files with 263 additions and 266 deletions

View File

@@ -49,11 +49,8 @@ int UnityMain(int argc, const char* argv[], void (*runAllTests)(void));
}\
void TEST_##group##_##name##_(void)
#define DECLARE_TEST_CASE(group, name) \
void TEST_##group##_##name##_run(void)
#define RUN_TEST_CASE(group, name) \
{ DECLARE_TEST_CASE(group, name);\
{ void TEST_##group##_##name##_run(void);\
TEST_##group##_##name##_run(); }
//This goes at the bottom of each test file or in a separate c file
@@ -72,8 +69,8 @@ int UnityMain(int argc, const char* argv[], void (*runAllTests)(void));
TEST_##group##_GROUP_RUNNER(); }
//CppUTest Compatibility Macros
#define UT_PTR_SET(ptr, newPointerValue) UnityPointer_Set((void**)&ptr, (void*)newPointerValue)
#define TEST_ASSERT_POINTERS_EQUAL(expected, actual) TEST_ASSERT_EQUAL_PTR(expected, actual)
#define UT_PTR_SET(ptr, newPointerValue) UnityPointer_Set((void**)&(ptr), (void*)(newPointerValue))
#define TEST_ASSERT_POINTERS_EQUAL(expected, actual) TEST_ASSERT_EQUAL_PTR((expected), (actual))
#define TEST_ASSERT_BYTES_EQUAL(expected, actual) TEST_ASSERT_EQUAL_HEX8(0xff & (expected), 0xff & (actual))
#define FAIL(message) TEST_FAIL_MESSAGE((message))
#define CHECK(condition) TEST_ASSERT_TRUE((condition))