diff options
Diffstat (limited to 'unit/src/unit.c')
| -rwxr-xr-x | unit/src/unit.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/unit/src/unit.c b/unit/src/unit.c new file mode 100755 index 0000000..a5f143c --- /dev/null +++ b/unit/src/unit.c @@ -0,0 +1,56 @@ +#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"); + fflush(stdout); + current = current->next; + } + + return 0; +} + |
