Skip to content

Commit caf4e48

Browse files
nordic-krchpdgendt
authored andcommitted
tests: unit: util: Extend FOR_EACH test
Extend test to check also no arguments. Signed-off-by: Krzysztof Chruściński <[email protected]>
1 parent 12ff44b commit caf4e48

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tests/unit/util/main.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ ZTEST(util, test_IN_RANGE) {
236236

237237
ZTEST(util, test_FOR_EACH) {
238238
#define FOR_EACH_MACRO_TEST(arg) *buf++ = arg
239+
#define FOR_EACH_MACRO_TEST2(arg) arg
239240

240241
uint8_t array[3] = {0};
241242
uint8_t *buf = array;
@@ -245,6 +246,14 @@ ZTEST(util, test_FOR_EACH) {
245246
zassert_equal(array[0], 1, "Unexpected value %d", array[0]);
246247
zassert_equal(array[1], 2, "Unexpected value %d", array[1]);
247248
zassert_equal(array[2], 3, "Unexpected value %d", array[2]);
249+
250+
uint8_t test0[] = { 0, FOR_EACH(FOR_EACH_MACRO_TEST2, (,))};
251+
252+
BUILD_ASSERT(sizeof(test0) == 1, "Unexpected length due to FOR_EACH fail");
253+
254+
uint8_t test1[] = { 0, FOR_EACH(FOR_EACH_MACRO_TEST2, (,), 1)};
255+
256+
BUILD_ASSERT(sizeof(test1) == 2, "Unexpected length due to FOR_EACH fail");
248257
}
249258

250259
ZTEST(util, test_FOR_EACH_NONEMPTY_TERM) {

0 commit comments

Comments
 (0)