BFLibC 0.1
C Library
Loading...
Searching...
No Matches
bftests.h
Go to the documentation of this file.
1
6#ifndef BF_TESTS_H
7#define BF_TESTS_H
8
9#include <stdio.h>
10#include <stdlib.h>
11
12#define INTRO_TEST_FUNCTION printf("Running %s:\n", __func__)
13#define PRINT_TEST_RESULTS(result) \
14 if (result) {system("printf \"[\033[0;32m Pass \033[0m] \"");}\
15 else {system("printf \"[\033[0;31m Fail \033[0m] \"");}\
16 printf("%s\n", __func__)
17
18// Use these to show progress
19#define UNIT_TEST_START printf("[ .... ] %s", __func__); fflush(stdout);
20#define UNIT_TEST_END(result, errcode) \
21 printf("\r");fflush(stdout);\
22 if (result) {system("printf \"[\033[0;32m Pass \033[0m] \"");}\
23 else {system("printf \"[\033[0;31m Fail \033[0m] \"");}\
24 printf("%s", __func__);\
25 if (!result) printf(" - [%d]", errcode);\
26 printf("\n")
27
31#define LAUNCH_TEST(unit_test_function, pass_counter, fail_counter) \
32 if (!unit_test_function()) pass_counter++; \
33 else fail_counter++;
34
35#define PRINT_GRADE(p, f) printf("Grade - %.2f%% (%d/%d)\n", (float) ((p/(p+f)) * 100), (int) p, (int) (p+f));
36
37#define TEST_SUITE_START int pass = 0, fail = 0;\
38 float tp = 0, tf = 0;
39
40#define LAUNCH_TEST_SET(foo) foo(&pass, &fail);\
41 printf("[+ %d, - %d]\n", pass, fail);\
42 tp += pass; tf += fail;\
43 pass = 0; fail = 0;
44
45#define TEST_SUITE_END PRINT_GRADE(tp, tf)
46
47#endif // BF_TESTS_H
48