diff options
| author | 2026-02-23 20:36:05 +0100 | |
|---|---|---|
| committer | 2026-02-23 20:36:05 +0100 | |
| commit | 052144cabb126efe925a96f8a0597a0f2005d206 (patch) | |
| tree | 4fd87244b9eef018b30e90fdff24c5b1a145a85e /test/external/metalang99/examples/assert_for_each.c | |
| parent | 4e9020dfb847d80475415f9f5914efaa50238767 (diff) | |
add metalang99 testsuite (preprocessor stress testing)
Diffstat (limited to 'test/external/metalang99/examples/assert_for_each.c')
| -rw-r--r-- | test/external/metalang99/examples/assert_for_each.c | 31 |
1 files changed, 31 insertions, 0 deletions
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 <metalang99.h> + +#include <assert.h> + +#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'); + */ +} |