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/unit/src/Unit.c

62 lines
1.0 KiB
C
Raw Normal View History

#include <BH/Unit.h>
2025-01-18 17:24:36 +03:00
#include <stdlib.h>
typedef struct BH_Unit
2025-01-18 17:24:36 +03:00
{
struct BH_Unit *next;
2025-01-18 17:24:36 +03:00
const char *name;
BH_UnitCallback cb;
} BH_Unit;
2025-01-18 17:24:36 +03:00
static BH_Unit *root = NULL;
void BH_UnitAdd(const char *name, BH_UnitCallback cb)
2025-01-18 17:24:36 +03:00
{
BH_Unit *unit, *current;
2025-01-18 17:24:36 +03:00
/* Allocate and fill new unit test entry */
2025-01-18 17:24:36 +03:00
unit = malloc(sizeof(*unit));
if (!unit)
return;
unit->next = NULL;
unit->name = name;
unit->cb = cb;
2025-01-18 17:24:36 +03:00
/* Append unit test entry */
2025-01-18 17:24:36 +03:00
current = root;
while (current && current->next)
current = current->next;
if (current)
current->next = unit;
else
root = unit;
}
int BH_UnitRun(void)
2025-01-18 17:24:36 +03:00
{
BH_Unit *current;
2025-01-18 17:24:36 +03:00
printf("Running tests...\n");
current = root;
while (current)
{
printf("%s\n", current->name);
if (current->cb())
2025-01-18 17:24:36 +03:00
{
printf("\tFAIL\n");
return -1;
}
printf("\tPASS\n");
fflush(stdout);
current = current->next;
}
return 0;
}