dumb framework to run unit tests in terminology

devs/bu5hm4n/fix-for-billiob
Boris Faure 3 years ago
parent 392bfdb4a7
commit 63815156aa
Signed by: borisfaure
GPG Key ID: 35C0410516166BE8
  1. 76
      src/bin/tytest.c
  2. 5
      src/bin/tytest.h
  3. 7
      src/bin/tytest_common.c

@ -14,12 +14,83 @@
#include "termpty.h"
#include "termptyops.h"
#include "termiointernals.h"
#include "tytest.h"
#include "tytest_common.h"
#include "md5/md5.h"
int _log_domain = -1;
/* {{{ Unit tests */
static struct {
const char *name;
tytest_func func;
} _tytests[] = {
{ "dummy", tytest_dummy },
{ NULL, NULL},
};
static int
_run_this_tytest(const char *name, tytest_func func)
{
int res;
fprintf(stderr, "\033[0m%s...", name);
res = func();
fprintf(stderr, " %s\n", res == 0 ? "\033[32m✔" : "\033[31;1m×");
return res;
}
static tytest_func
_find_tytest(const char *name)
{
int ntests = (sizeof(_tytests) / sizeof(_tytests[0])) - 1;
int i;
for (i = 0; i < ntests; i++)
{
if (strcmp(name, _tytests[i].name) == 0)
return _tytests[i].func;
}
return NULL;
}
static int
_run_all_tytests(void)
{
int ntests = (sizeof(_tytests) / sizeof(_tytests[0])) - 1;
int i, res = 0;
for (i = 0; res == 0 && i < ntests; i++)
res = _run_this_tytest(_tytests[i].name, _tytests[i].func);
return res;
}
static int
_run_tytests(int argc, char **argv)
{
int i, res = 0;
for (i = 1; res == 0 && i < argc; i++)
{
if (strncmp(argv[i], "all", strlen("all")) == 0)
res = _run_all_tytests();
else
{
tytest_func func = _find_tytest(argv[i]);
if (!func)
{
fprintf(stderr, "can not find test named '%s'\n", argv[i]);
return -1;
}
res = _run_this_tytest(argv[i], func);
}
}
return res;
}
/* }}} */
typedef struct _Termpty_Tests
{
size_t backsize, backpos;
@ -122,8 +193,11 @@ _tytest_checksum(Termpty *ty)
int
main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
main(int argc, char **argv)
{
if (argc > 1)
return _run_tytests(argc, argv);
eina_init();
_log_domain = eina_log_domain_register("tytest", NULL);

@ -28,4 +28,9 @@ test_pointer_canvas_xy_get(int *mx,
void test_set_mouse_pointer(int mx, int my);
#endif
/* Unit tests */
typedef int (*tytest_func)(void);
int tytest_dummy(void);
#endif

@ -445,3 +445,10 @@ tytest_common_set_fd(int fd)
_ty.fd = fd;
assert(_ty.fd >= 0);
}
/* dummy unit test */
int
tytest_dummy(void)
{
return 0;
}

Loading…
Cancel
Save