save
[protos/libecoli.git] / lib / ecoli_test.h
index a05d4cf..1cebe95 100644 (file)
 #include <sys/queue.h>
 
 #include <ecoli_log.h>
-#include <ecoli_tk.h>
+#include <ecoli_node.h>
 
-#define EC_REGISTER_TEST(t)                                            \
-       static void ec_init_##t(void);                                  \
-       static void __attribute__((constructor, used)) ec_init_##t(void) \
+// XXX check if already exists?
+#define EC_TEST_REGISTER(t)                                            \
+       static void ec_test_init_##t(void);                             \
+       static void __attribute__((constructor, used))                  \
+       ec_test_init_##t(void)                                          \
        {                                                               \
                 ec_test_register(&t);                                  \
        }
@@ -66,32 +68,37 @@ struct ec_test {
 void ec_test_register(struct ec_test *test);
 
 int ec_test_all(void);
+int ec_test_one(const char *name);
 
 /* expected == -1 means no match */
-int ec_test_check_tk_parse(struct ec_tk *tk, int expected, ...);
+int ec_test_check_parse(struct ec_node *node, int expected, ...);
 
 #define EC_TEST_ERR(fmt, ...)                                          \
-       ec_log(EC_LOG_ERR, "%s:%d: error: " fmt "\n",                   \
+       EC_LOG(EC_LOG_ERR, "%s:%d: error: " fmt "\n",                   \
                __FILE__, __LINE__, ##__VA_ARGS__);                     \
 
-#define EC_TEST_ASSERT(cond, args...)                                  \
+/* XXX this is not an assert, it does not abort */
+#define EC_TEST_ASSERT_STR(cond, fmt, ...)                             \
        do {                                                            \
                if (!(cond))                                            \
-                       EC_TEST_ERR("assertion failure: " #cond);       \
+                       EC_TEST_ERR("assert failure: (" #cond ") " fmt, \
+                               ##__VA_ARGS__);                         \
        } while (0)
 
-/* tk, input, [expected1, expected2, ...] */
-#define EC_TEST_CHECK_TK_PARSE(tk, args...) ({         \
-       int ret_ = ec_test_check_tk_parse(tk, args, EC_TK_ENDLIST);     \
+#define EC_TEST_ASSERT(cond) EC_TEST_ASSERT_STR(cond, "")
+
+/* node, input, [expected1, expected2, ...] */
+#define EC_TEST_CHECK_PARSE(node, args...) ({                          \
+       int ret_ = ec_test_check_parse(node, args, EC_NODE_ENDLIST);    \
        if (ret_)                                                       \
                EC_TEST_ERR("parse test failed");                       \
        ret_;                                                           \
 })
 
-int ec_test_check_tk_complete(const struct ec_tk *tk, ...);
+int ec_test_check_complete(struct ec_node *node, ...);
 
-#define EC_TEST_CHECK_TK_COMPLETE(tk, args...) ({                      \
-       int ret_ = ec_test_check_tk_complete(tk, args);                 \
+#define EC_TEST_CHECK_COMPLETE(node, args...) ({                       \
+       int ret_ = ec_test_check_complete(node, args);                  \
        if (ret_)                                                       \
                EC_TEST_ERR("complete test failed");                    \
        ret_;                                                           \