aboutsummaryrefslogtreecommitdiff
path: root/test/include/test.h
blob: 74642b7cbf6af804c2850bcc52b3c59cde2d4e73 (plain) (blame)
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
#ifndef TEST_H
#define TEST_H

#include "../../src/include/util.h"

/* 
   This is probably how it's supposed to work. In what other cases would you
   need `extern`?
*/
extern unsigned int TESTS_RUN;
extern unsigned int TESTS_PASSED;

#define TEST_INIT unsigned int TESTS_RUN = 0, TESTS_PASSED = 0;

#define ASSERT(EXPR) \
   TESTS_RUN++; \
   if (EXPR && ++TESTS_PASSED) { \
      LOG_INFF("%s:%s:%d: Assertion passed!", __FILE__, __func__, __LINE__); \
   } else { \
      LOG_ERRF("Assertion failed:\n\t%s", #EXPR); \
   }

#define TEST_REPORT \
   if (TESTS_RUN == TESTS_PASSED) { \
      LOG_YAYF("%s: All %d tests passed!", __FILE__, TESTS_RUN); \
   } else { \
      LOG_ERRF("%d/%d tests failed.", TESTS_RUN - TESTS_PASSED, TESTS_RUN); \
   }

#endif