1
0
mirror of https://github.com/ThrowTheSwitch/Unity.git synced 2026-01-23 00:15:58 +01:00

Wrap UNITY_TEST_ASSERT in a do ... while(0) block

This ensures that constructions like the following work correctly:

  if(condition)
    TEST_ASSERT(a);
  else
    TEST_ASSERT(b);
This commit is contained in:
John Lindgren
2020-04-09 13:03:16 -04:00
parent 10fd84f02b
commit 2485d49d13
2 changed files with 14 additions and 1 deletions

View File

@@ -133,6 +133,19 @@ void testFalse(void)
TEST_ASSERT_UNLESS(0);
}
void testSingleStatement(void)
{
for(int i = 0; i < 2; i++)
{
/* TEST_ASSERT_TRUE should expand to a single C statement, minus
* the semicolon. This if-else will fail to compile otherwise. */
if(i > 0)
TEST_ASSERT_TRUE(i);
else
TEST_ASSERT_FALSE(i);
}
}
void testPreviousPass(void)
{
TEST_ASSERT_EQUAL_INT(0U, Unity.TestFailures);