block -> va_args

having them as blocks causes issues when a struct with values is initialized
inside the block, because the compiler treats the comma in the struct
defenition as seperate arguments.
This commit is contained in:
Adwaith-Rajesh 2025-09-28 12:34:05 +05:30
parent 25b0e92ed0
commit c1c3e87444
Signed by: Adwaith-Rajesh
GPG Key ID: 98CC7C030DF895A0

4
test.h
View File

@ -36,7 +36,7 @@ static test_func_t test_functions[MAX_TEST_FUNCS];
return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; \ return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; \
} }
#define TEST(NAME, BLOCK) \ #define TEST(NAME, ...) \
static int test_##NAME(); \ static int test_##NAME(); \
__attribute__((constructor)) static void register_test_##NAME() { \ __attribute__((constructor)) static void register_test_##NAME() { \
if (total < MAX_TEST_FUNCS) { \ if (total < MAX_TEST_FUNCS) { \
@ -50,7 +50,7 @@ static test_func_t test_functions[MAX_TEST_FUNCS];
printf("\ntest_" #NAME "\n"); \ printf("\ntest_" #NAME "\n"); \
int total_assert = 0; \ int total_assert = 0; \
int total_success = 0; \ int total_success = 0; \
BLOCK \ __VA_ARGS__ \
printf("\t(%d/%d) passed (%d) failed\n", total_success, total_assert, total_assert - total_success); \ printf("\t(%d/%d) passed (%d) failed\n", total_success, total_assert, total_assert - total_success); \
return (total_assert == total_success); \ return (total_assert == total_success); \
} }