struct ec_strvec;
struct ec_keyval;
-#define EC_NODE_TYPE_REGISTER(t) \
+#define EC_NODE_TYPE_REGISTER(t) \
static void ec_node_init_##t(void); \
static void __attribute__((constructor, used)) \
ec_node_init_##t(void) \
{ \
if (ec_node_type_register(&t) < 0) \
- fprintf(stderr, "cannot register %s\n", t.name); \
+ fprintf(stderr, \
+ "cannot register node type %s\n", \
+ t.name); \
}
TAILQ_HEAD(ec_node_type_list, ec_node_type);
#include <stdio.h>
#include <string.h>
#include <assert.h>
+#include <errno.h>
#include <ecoli_log.h>
#include <ecoli_malloc.h>
EC_LOG_TYPE_REGISTER(test);
-/* register a test case */
-void ec_test_register(struct ec_test *test)
+static struct ec_test *ec_test_lookup(const char *name)
{
+ struct ec_test *test;
+
+ TAILQ_FOREACH(test, &test_list, next) {
+ if (!strcmp(name, test->name))
+ return test;
+ }
+
+ errno = EEXIST;
+ return NULL;
+}
+
+int ec_test_register(struct ec_test *test)
+{
+ if (ec_test_lookup(test->name) != NULL)
+ return -1;
+
TAILQ_INSERT_TAIL(&test_list, test, next);
- // XXX check if already exist, like for type
+
+ return 0;
}
int ec_test_check_parse(struct ec_node *tk, int expected, ...)
struct ec_node;
enum ec_completed_type;
-// 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); \
+ if (ec_test_register(&t) < 0) \
+ fprintf(stderr, "cannot register test %s\n", \
+ t.name); \
}
/**
* @param test
* A pointer to a ec_test structure describing the test
* to be registered.
+ * @return
+ * 0 on success, -1 on error (errno is set).
*/
-void ec_test_register(struct ec_test *test);
+int ec_test_register(struct ec_test *test);
int ec_test_all(void);
int ec_test_one(const char *name);