From 052144cabb126efe925a96f8a0597a0f2005d206 Mon Sep 17 00:00:00 2001 From: lemon Date: Mon, 23 Feb 2026 20:36:05 +0100 Subject: add metalang99 testsuite (preprocessor stress testing) --- .../external/metalang99/examples/assert_for_each.c | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 test/external/metalang99/examples/assert_for_each.c (limited to 'test/external/metalang99/examples/assert_for_each.c') diff --git a/test/external/metalang99/examples/assert_for_each.c b/test/external/metalang99/examples/assert_for_each.c new file mode 100644 index 0000000..3ba9127 --- /dev/null +++ b/test/external/metalang99/examples/assert_for_each.c @@ -0,0 +1,31 @@ +// Asserts multiple expressions at once. + +#include + +#include + +#define ASSERT_FOR_EACH(...) \ + do { \ + ML99_EVAL(ML99_variadicsForEach( \ + ML99_compose(v(ML99_semicoloned), ML99_reify(v(assert))), \ + v(__VA_ARGS__))) \ + } while (0) + +int main(void) { + ASSERT_FOR_EACH(123 == 123, 2 + 2 == 4, "foo"[1] == 'o'); + + /* + * If we combine multiple assertions with the && operator, we will not be able to distinguish + * them if one of them fails apparently: + * + * main: Assertion `123 == 321 && 2 + 2 == 4 && "foo"[1] == 'o' failed. + * assert(123 == 321 && 2 + 2 == 4 && "foo"[1] == 'o'); + */ + + /* + * ... unlike `ASSERT_FOR_EACH` telling us which one has failed: + * + * main: Assertion `123 == 321' failed. + * ASSERT_FOR_EACH(123 == 321, 2 + 2 == 4, "foo"[1] == 'o'); + */ +} -- cgit v1.2.3