aboutsummaryrefslogtreecommitdiff
path: root/test/main.c
blob: ebfe3dab163974439f918ca382c77de82e181b6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include <stdatomic.h>
#include <time.h>
#include "test_framework.h"
#include "test_declarations.h"

#define STR_(x) #x
#define STR(x) STR_(x)


// Referred to via extern in 'test_framework.c'
atomic_flag test_framework_assertion_failed = ATOMIC_FLAG_INIT;


static void report(const char *clr, const char *label, const char *name, clock_t taken) {
	printf("\x1B[%sm[%s] %s (%lfs)\n",
			clr, label, name, (double)taken / CLOCKS_PER_SEC);
}

static void report_success(const char *name, clock_t taken) {
	report("32", "  OK  ", name, taken);
}

static void report_failure(const char *name, clock_t taken) {
	report("31", "FAILED", name, taken);
}

#define RUN_TEST(name) do { \
		atomic_flag_clear(&test_framework_assertion_failed); \
		clock_t start_ = clock(); \
		int ret_ = TEST(name)(); \
		clock_t diff_ = clock() - start_; \
		if (ret_ == 0 && !atomic_flag_test_and_set(&test_framework_assertion_failed)) { \
			report_success(STR(name), diff_); \
		} else { \
			report_failure(STR(name), diff_); \
			return 1; \
		} \
	} while (0)

static int run_tests(void) {
	RUN_TEST(hashtable);
	return 0;
}


int main(void) {
	return run_tests();
}