summaryrefslogtreecommitdiff
path: root/tests/test.c
blob: a919301988a2b8b46a7d02b73c9975271c5456e1 (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
50
51
52
53
54
55
56
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#define COLOR_RED    "\e[31m"
#define COLOR_GREEN  "\e[32m"
#define COLOR_R      "\e[0m"

#define GET_RES(func) {\
  int res = func();\
  if (res > 0) {\
    /*printf(COLOR_RED "Case " #func " failed" COLOR_R "\n");*/\
    failed_cases += 1;\
  }\
  failed_assertions += res;\
}

enum TestCases {
#define CASE(__case__) TestCase_##__case__ ,
#include "cases_list.h"
#undef CASE
  TestCase_MAXCASES,
};

#define CASE(__case__) \
extern unsigned __case__();
#include "cases_list.h"
#undef CASE

unsigned ((*test_cases[TestCase_MAXCASES])(void)) = {
#define CASE(__case__) [TestCase_##__case__] = &(__case__),
#include "cases_list.h"
#undef CASE
};

int total_assertions = 0;

int main () {
  int failed_assertions = 0;
  int failed_cases = 0;

  for (int i = 0; i < TestCase_MAXCASES; i++) {
    GET_RES(test_cases[i]);
  }

  if (!failed_assertions) {
    printf(COLOR_GREEN "All tests passed!\n" COLOR_R);
    exit(EXIT_SUCCESS);
  } else {
    puts("\n=================================== TEST SUMMARY ================================\n");
    printf(COLOR_GREEN "Pass: %d \t" COLOR_RED "Failed: %d\n" COLOR_R, total_assertions - failed_assertions, failed_assertions);
    exit(EXIT_FAILURE);
  }

  return 0;
}