]> git.ozlabs.org Git - ccan/blobdiff - ccan/cppmagic/test/run.c
cppmagic: New module
[ccan] / ccan / cppmagic / test / run.c
diff --git a/ccan/cppmagic/test/run.c b/ccan/cppmagic/test/run.c
new file mode 100644 (file)
index 0000000..0ed830d
--- /dev/null
@@ -0,0 +1,34 @@
+#include "config.h"
+
+#include <string.h>
+
+#include <ccan/cppmagic/cppmagic.h>
+#include <ccan/tap/tap.h>
+
+static inline void check1(const char *orig, const char *expand,
+                         const char *match)
+{
+       ok(strcmp(expand, match) == 0,
+          "%s => %s : %s", orig, expand, match);
+}
+
+#define CHECK1(orig, match) \
+       check1(#orig, CPPMAGIC_STRINGIFY(orig), match)
+
+int main(void)
+{
+       plan_tests(7);
+
+       CHECK1(CPPMAGIC_NOTHING(), "");
+       CHECK1(CPPMAGIC_GLUE2(a, b), "ab");
+
+       CHECK1(CPPMAGIC_1ST(a), "a");
+       CHECK1(CPPMAGIC_1ST(a, b), "a");
+       CHECK1(CPPMAGIC_1ST(a, b, c), "a");
+
+       CHECK1(CPPMAGIC_2ND(a, b), "b");
+       CHECK1(CPPMAGIC_2ND(a, b, c), "b");
+
+       /* This exits depending on whether all tests passed */
+       return exit_status();
+}