libei/test/libei-unit-test.c
Peter Hutterer 0ab1458241 test: add some internal unit-tests to libei
Similar in style to Rust where the unit tests are in the same file. Let's see
how far we can get with that in C. Auto-discovery of tests by forcing the
respective suites into a special test section so we can collect it later from
our unit runner.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-06 14:47:40 +10:00

35 lines
632 B
C

#include "config.h"
#include <assert.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <munit.h>
extern const MunitSuite __start_test_section, __stop_test_section;
int
main(int argc, char* argv[MUNIT_ARRAY_PARAM(argc + 1)])
{
size_t sz = 10;
size_t count = 0;
MunitSuite *suites = calloc(sz, sizeof(*suites));
for (const MunitSuite *s = &__start_test_section;
s < &__stop_test_section;
s++) {
assert(count < sz - 1);
suites[count] = *s;
count++;
}
const MunitSuite suite = {
"/ei",
NULL,
suites,
1,
MUNIT_SUITE_OPTION_NONE,
};
return munit_suite_main(&suite, NULL, argc, argv);
}