aboutsummaryrefslogtreecommitdiff
path: root/unit/src/unit.c
diff options
context:
space:
mode:
Diffstat (limited to 'unit/src/unit.c')
-rw-r--r--unit/src/unit.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/unit/src/unit.c b/unit/src/unit.c
new file mode 100644
index 0000000..95de080
--- /dev/null
+++ b/unit/src/unit.c
@@ -0,0 +1,55 @@
+#include <bh/unit.h>
+#include <stdlib.h>
+
+typedef struct bh_unit_s
+{
+ struct bh_unit_s *next;
+ const char *name;
+ bh_unit_cb_t func;
+} bh_unit_t;
+
+static bh_unit_t *root = NULL;
+
+void bh_unit_add(const char *name, bh_unit_cb_t func)
+{
+ bh_unit_t *unit, *current;
+
+ unit = malloc(sizeof(*unit));
+ if (!unit)
+ return;
+
+ unit->name = name;
+ unit->func = func;
+ unit->next = NULL;
+
+ current = root;
+ while (current && current->next)
+ current = current->next;
+
+ if (current)
+ current->next = unit;
+ else
+ root = unit;
+}
+
+int bh_unit_run(void)
+{
+ bh_unit_t *current;
+ printf("Running tests...\n");
+
+ current = root;
+ while (current)
+ {
+ printf("%s\n", current->name);
+ if (current->func())
+ {
+ printf("\tFAIL\n");
+ return -1;
+ }
+ printf("\tPASS\n");
+ current = current->next;
+ }
+
+ return 0;
+}
+