Hi,
> I just stumbled upon MinUnit[0], a 3-line unit test framework for C. Do you know
> other similarly simple solutions?
I wrote ago a simple framework for it long time:
test.h:
#ifndef UTEST_H_
#define UTEST_H_
#ifdef NDEBUG
#undef NDEBUG
#endif
#include <signal.h>
#include <setjmp.h>
#include <stdio.h>
#include <assert.h>
int utst_actual_test;
int utst_test_ok;
jmp_buf utst_jmp;
static void utst_sigabrt(int dummy)
{
longjmp(utst_jmp, 0);
}
#define run_test(message, test) do { \
printf("Test %d %s ... ", utst_actual_test, message); \
signal(SIGABRT, utst_sigabrt); \
++utst_actual_test; \
if (!setjmp(utst_jmp)) { \
assert(test); \
puts("OK"); \
++utst_test_ok; \
} else { \
puts("FAILED"); \
} \
fflush(stdin); \
}while (0)
#define run_end() do { \
if (utst_actual_test == utst_test_ok) \
puts("ALL TEST PASSED"); \
else \
printf("FAILED %d TESTS\n", \
utst_actual_test - utst_test_ok); \
utst_test_ok = 0; \
utst_actual_test = 0; \
} while (0)
#endif /* UTEST_H_ */
--
Roberto E. Vargas Caballero
Received on Thu Jul 31 2014 - 11:20:26 CEST