This repository has been archived on 2026-04-17. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
bhlib-old/unit/src/unit.c

54 lines
881 B
C

#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;
static bh_unit_t *last = NULL;
void bh_unit_add(const char *name, bh_unit_cb_t func)
{
bh_unit_t *unit;
unit = malloc(sizeof(*unit));
if (!unit)
return;
unit->name = name;
unit->func = func;
unit->next = NULL;
if (last)
last->next = unit;
else
root = unit;
last = 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;
}