blob: 12d251eb45c72e434c309631440b173754dabc23 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#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;
}
|