nu unit
#define nu_assert(exp) do { if (!(exp)) return #exp; } while (0)
#define nu_run_test(test) do { \
const char *mesg = test(); nu_tests_run++; \
if (mesg) printf("[failed] " #test " : %s\n", mesg); \
else nu_tests_ok++; \
} while (0)
#define nu_result() (nu_tests_run - nu_tests_ok)
extern int nu_tests_run, nu_tests_ok;
#include <stdio.h>
#include "nu_unit.h"
int nu_tests_run, nu_tests_ok;
int foo = 7;
int bar = 4;
static char *
t01()
{
nu_assert(foo == 7);
return NULL;
}
static char *
t02()
{
nu_assert(bar == 5);
return NULL;
}
static void
all()
{
nu_run_test(t01);
nu_run_test(t02);
}
int
main(int argc, char **argv)
{
all();
if (nu_result())
printf("[\033[31mFAILED\033[0m] %d passed / ", nu_tests_ok);
else
printf("[\033[32m OK \033[0m] ALL TEST PASSED : ");
printf("%d total\n", nu_tests_run);
return !!nu_result();
}
% ./example
[failed] t02 : bar == 5
[FAILED] 1 passed / 2 total
parent directory