X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Fecoli_test.h;h=01158379a8b598350d6902474cb2a5f500033eb8;hb=c49beb1e5cee2b36c916c64c571967d8ef19c58a;hp=45d1d4e1ea93c1df663e11311cec89b1916bd2c5;hpb=0ae8acfbbe4820ccf222c49d8c49aa45202f4f18;p=protos%2Flibecoli.git diff --git a/lib/ecoli_test.h b/lib/ecoli_test.h index 45d1d4e..0115837 100644 --- a/lib/ecoli_test.h +++ b/lib/ecoli_test.h @@ -31,11 +31,13 @@ #include #include -#include +#include -#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,39 +68,36 @@ struct ec_test { void ec_test_register(struct ec_test *test); int ec_test_all(void); - -int ec_test_check_tk_parse(const struct ec_tk *tk, const char *input, - const char *expected); - -#define TEST_ERR() \ - ec_log(EC_LOG_ERR, "%s:%d: error: test failed\n", \ - __FILE__, __LINE__); \ - -#define EC_TEST_CHECK_TK_PARSE(tk, input, expected) ({ \ - int ret = ec_test_check_tk_parse(tk, input, expected); \ - if (ret) \ - TEST_ERR(); \ - ret; \ -}) - -int ec_test_check_tk_complete(const struct ec_tk *tk, const char *input, - const char *expected); - -#define EC_TEST_CHECK_TK_COMPLETE(tk, input, expected) ({ \ - int ret = ec_test_check_tk_complete(tk, input, expected); \ - if (ret) \ - TEST_ERR(); \ - ret; \ +int ec_test_one(const char *name); + +/* expected == -1 means no match */ +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", \ + __FILE__, __LINE__, ##__VA_ARGS__); \ + +#define EC_TEST_ASSERT(cond, args...) \ + do { \ + if (!(cond)) \ + EC_TEST_ERR("assertion failure: " #cond); \ + } while (0) + +/* 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_list(const struct ec_tk *tk, - const char *input, ...); +int ec_test_check_complete(struct ec_node *node, ...); -#define EC_TEST_CHECK_TK_COMPLETE_LIST(tk, input, expected...) ({ \ - int ret = ec_test_check_tk_complete_list(tk, input, expected); \ - if (ret) \ - TEST_ERR(); \ - ret; \ +#define EC_TEST_CHECK_COMPLETE(node, args...) ({ \ + int ret_ = ec_test_check_complete(node, args); \ + if (ret_) \ + EC_TEST_ERR("complete test failed"); \ + ret_; \ }) #endif