summaryrefslogtreecommitdiff
path: root/source/kit_test/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/kit_test/test.c')
-rw-r--r--source/kit_test/test.c94
1 files changed, 46 insertions, 48 deletions
diff --git a/source/kit_test/test.c b/source/kit_test/test.c
index 3d3e180..6603d65 100644
--- a/source/kit_test/test.c
+++ b/source/kit_test/test.c
@@ -10,13 +10,13 @@
kit_tests_list_t kit_tests_list = { 0 };
static void report(int i, int line, int ok) {
- int const n = kit_tests_list.tests[i].assertions++;
+ int const n = kit_tests_list.v[i].assertions++;
if (n >= KIT_TEST_ASSERTIONS_LIMIT)
return;
- kit_tests_list.tests[i].line[n] = line;
- kit_tests_list.tests[i].status[n] = ok;
+ kit_tests_list.v[i].line[n] = line;
+ kit_tests_list.v[i].status[n] = ok;
}
static long long ns_to_ms(long long ns) {
@@ -42,10 +42,10 @@ void kit_test_register(char const *name, char const *file,
kit_test_run_fn fn) {
int n = kit_tests_list.size++;
if (n < KIT_TESTS_SIZE_LIMIT) {
- kit_tests_list.tests[n].test_fn = fn;
- kit_tests_list.tests[n].test_name = name;
- kit_tests_list.tests[n].test_file = file;
- kit_tests_list.tests[n].assertions = 0;
+ kit_tests_list.v[n].test_fn = fn;
+ kit_tests_list.v[n].test_name = name;
+ kit_tests_list.v[n].test_file = file;
+ kit_tests_list.v[n].assertions = 0;
}
}
@@ -71,7 +71,8 @@ static void setup_signals() {
int i;
for (i = 0; i < sizeof signums / sizeof *signums; i++) {
-#if defined(_WIN32) && !(defined __CYGWIN__)
+#if (defined(_WIN32) && !defined(__CYGWIN__)) || \
+ !defined(_POSIX_C_SOURCE)
signal(signums[i], handle_signal);
#else
struct sigaction action;
@@ -87,11 +88,11 @@ static int run_test(volatile int i) {
int signum = setjmp(kit_test_restore_execution);
if (signum != 0) {
- kit_tests_list.tests[i].signal = signum;
+ kit_tests_list.v[i].signal = signum;
return 0;
}
- kit_tests_list.tests[i].test_fn(i, report);
+ kit_tests_list.v[i].test_fn(i, report);
return 1;
}
@@ -139,30 +140,29 @@ int kit_run_tests(int argc, char **argv) {
for (i = 0; i < kit_tests_list.size && i < KIT_TESTS_SIZE_LIMIT;
i++) {
if (specific_test != NULL &&
- strstr(kit_tests_list.tests[i].test_name, specific_test) ==
- NULL)
+ strstr(kit_tests_list.v[i].test_name, specific_test) == NULL)
continue;
tests_total++;
- int const l = 2 + (int) strlen(kit_tests_list.tests[i].test_name);
+ int const l = 2 + (int) strlen(kit_tests_list.v[i].test_name);
if (line_width < l)
line_width = l;
}
if (tests_total > 0) {
- char const *const s = kit_tests_list.tests[0].test_file;
+ char const *const s = kit_tests_list.v[0].test_file;
for (j = 1; j < kit_tests_list.size && j < KIT_TESTS_SIZE_LIMIT;
j++) {
if (specific_test != NULL &&
- strstr(kit_tests_list.tests[j].test_name, specific_test) ==
+ strstr(kit_tests_list.v[j].test_name, specific_test) ==
NULL)
continue;
- if (strcmp(s, kit_tests_list.tests[j].test_file) == 0)
+ if (strcmp(s, kit_tests_list.v[j].test_file) == 0)
continue;
int k = 0;
- for (; s[k] != '\0' &&
- kit_tests_list.tests[j].test_file[k] != '\0' &&
- s[k] == kit_tests_list.tests[j].test_file[k];
+ for (;
+ s[k] != '\0' && kit_tests_list.v[j].test_file[k] != '\0' &&
+ s[k] == kit_tests_list.v[j].test_file[k];
k++) { }
if (file_root == -1 || file_root > k)
file_root = k;
@@ -178,14 +178,13 @@ int kit_run_tests(int argc, char **argv) {
for (i = 0; i < kit_tests_list.size && i < KIT_TESTS_SIZE_LIMIT;
i++) {
if (specific_test != NULL &&
- strstr(kit_tests_list.tests[i].test_name, specific_test) ==
- NULL)
+ strstr(kit_tests_list.v[i].test_name, specific_test) == NULL)
continue;
if (file == NULL ||
- strcmp(file, kit_tests_list.tests[i].test_file) != 0) {
+ strcmp(file, kit_tests_list.v[i].test_file) != 0) {
if (file != NULL)
quiet || printf("\n");
- file = kit_tests_list.tests[i].test_file;
+ file = kit_tests_list.v[i].test_file;
no_color || print_color(blue);
quiet || printf("* ");
no_color || print_color(white);
@@ -194,7 +193,7 @@ int kit_run_tests(int argc, char **argv) {
!carriage_return || no_color || print_color(yellow);
carriage_return || no_color || print_color(light);
- quiet || printf("` %s ", kit_tests_list.tests[i].test_name);
+ quiet || printf("` %s ", kit_tests_list.v[i].test_name);
!carriage_return || quiet || printf("\r");
quiet || fflush(stdout);
@@ -207,23 +206,22 @@ int kit_run_tests(int argc, char **argv) {
int duration = (int) (ns_to_ms(end.tv_nsec - begin.tv_nsec) +
sec_to_ms(end.tv_sec - begin.tv_sec));
- for (j = 0; j < kit_tests_list.tests[i].assertions; j++)
- if (kit_tests_list.tests[i].status[j] == 0) {
+ for (j = 0; j < kit_tests_list.v[i].assertions; j++)
+ if (kit_tests_list.v[i].status[j] == 0) {
fail_assertion_count++;
test_status = 0;
}
- if (kit_tests_list.tests[i].assertions >
- KIT_TEST_ASSERTIONS_LIMIT)
+ if (kit_tests_list.v[i].assertions > KIT_TEST_ASSERTIONS_LIMIT)
test_status = 0;
- total_assertion_count += kit_tests_list.tests[i].assertions;
+ total_assertion_count += kit_tests_list.v[i].assertions;
!carriage_return || no_color || print_color(light);
!carriage_return || quiet ||
- printf("` %s ", kit_tests_list.tests[i].test_name);
+ printf("` %s ", kit_tests_list.v[i].test_name);
- int const l = (int) strlen(kit_tests_list.tests[i].test_name);
+ int const l = (int) strlen(kit_tests_list.v[i].test_name);
quiet || printf("%*c", line_width - l, ' ');
if (test_status == 0) {
@@ -256,11 +254,11 @@ int kit_run_tests(int argc, char **argv) {
for (i = 0; i < kit_tests_list.size && i < KIT_TESTS_SIZE_LIMIT;
i++) {
if (specific_test != NULL &&
- strstr(kit_tests_list.tests[i].test_name, specific_test) ==
+ strstr(kit_tests_list.v[i].test_name, specific_test) ==
NULL)
continue;
- if (kit_tests_list.tests[i].signal != 0) {
- int signum = kit_tests_list.tests[i].signal;
+ if (kit_tests_list.v[i].signal != 0) {
+ int signum = kit_tests_list.v[i].signal;
if (signum >= 0 &&
signum < sizeof signames / sizeof *signames &&
signames[signum] != NULL) {
@@ -268,52 +266,52 @@ int kit_run_tests(int argc, char **argv) {
quiet || printf("Signal \"%s\" (%d) for \"",
signames[signum], signum);
no_color || print_color(white);
- quiet || printf("%s", kit_tests_list.tests[i].test_name);
+ quiet || printf("%s", kit_tests_list.v[i].test_name);
no_color || print_color(light);
quiet || printf("\" in \"");
no_color || print_color(white);
- quiet || printf("%s", kit_tests_list.tests[i].test_file +
- file_root);
+ quiet ||
+ printf("%s", kit_tests_list.v[i].test_file + file_root);
no_color || print_color(light);
quiet || printf("\"!.\n");
} else {
no_color || print_color(light);
quiet || printf("Unknown signal (%d) for \"", signum);
no_color || print_color(white);
- quiet || printf("%s", kit_tests_list.tests[i].test_name);
+ quiet || printf("%s", kit_tests_list.v[i].test_name);
no_color || print_color(light);
quiet || printf("\" in \"");
no_color || print_color(white);
- quiet || printf("%s", kit_tests_list.tests[i].test_file +
- file_root);
+ quiet ||
+ printf("%s", kit_tests_list.v[i].test_file + file_root);
no_color || print_color(light);
quiet || printf("\"!.\n");
}
}
- if (kit_tests_list.tests[i].assertions >
+ if (kit_tests_list.v[i].assertions >
KIT_TEST_ASSERTIONS_LIMIT) {
no_color || print_color(light);
quiet || printf("Too many assertions for \"");
no_color || print_color(white);
- quiet || printf("%s", kit_tests_list.tests[i].test_name);
+ quiet || printf("%s", kit_tests_list.v[i].test_name);
no_color || print_color(light);
quiet || printf("\" in \"");
no_color || print_color(white);
- quiet || printf("%s", kit_tests_list.tests[i].test_file +
- file_root);
+ quiet ||
+ printf("%s", kit_tests_list.v[i].test_file + file_root);
no_color || print_color(light);
quiet || printf("\"!.\n");
} else
- for (j = 0; j < kit_tests_list.tests[i].assertions; j++)
- if (!kit_tests_list.tests[i].status[j]) {
+ for (j = 0; j < kit_tests_list.v[i].assertions; j++)
+ if (!kit_tests_list.v[i].status[j]) {
no_color || print_color(light);
quiet || printf("Assertion on line ");
no_color || print_color(white);
- quiet || printf("%d", kit_tests_list.tests[i].line[j]);
+ quiet || printf("%d", kit_tests_list.v[i].line[j]);
no_color || print_color(light);
quiet || printf(" in \"");
no_color || print_color(white);
- quiet || printf("%s", kit_tests_list.tests[i].test_file +
+ quiet || printf("%s", kit_tests_list.v[i].test_file +
file_root);
no_color || print_color(light);
quiet || printf("\" failed.\n");