testing out macro magic to support positional, and keyword arguments with arbitrary default values
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
CC := gcc
|
CC := gcc
|
||||||
CFLAGS := -Wall -Wextra -O2 -fsanitize=address
|
CFLAGS := -Wall -Wextra -Wno-override-init -O2 -fsanitize=address
|
||||||
LDFLAGS := -lcriterion
|
LDFLAGS := -lcriterion
|
||||||
|
|
||||||
TESTBIN := /tmp/all_tests
|
TESTBIN := /tmp/all_tests
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
#include <criterion/criterion.h>
|
||||||
|
|
||||||
|
enum animal {
|
||||||
|
dog,
|
||||||
|
cat,
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct args {
|
||||||
|
enum animal animal;
|
||||||
|
} args_t;
|
||||||
|
|
||||||
|
#define ARGS_DEFAULT .animal=cat
|
||||||
|
#define ARGS(...) ((args_t){ ARGS_DEFAULT, __VA_ARGS__ })
|
||||||
|
|
||||||
|
Test(macro_magic, default_values) {
|
||||||
|
args_t a1 = ARGS();
|
||||||
|
args_t a2 = ARGS(.animal=dog);
|
||||||
|
cr_assert_eq(a1.animal, cat);
|
||||||
|
cr_assert_eq(a2.animal, dog);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user