-
Notifications
You must be signed in to change notification settings - Fork 0
/
minunit.h
50 lines (41 loc) · 1.43 KB
/
minunit.h
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
/*
* File: minunit.h
* Author: Zed. A. Shaw, Sam
*
* @see http://c.learncodethehardway.org/book/ex30.html
*
* Created on 27 August 2014, 22:14
*/
#ifndef MINUNIT_H_INCLUDED
#define MINUNIT_H_INCLUDED
#include <stdio.h>
#include <stdlib.h>
#define log_err(message) printf("\tError: %s\n", message)
#define mu_suite_start() char *message = NULL
#define mu_assert(test, message) \
do { \
if (!(test)) { \
log_err(message); \
return message; \
} \
} while(0)
#define mu_run_test(test) \
do { \
printf("\n-----%s", " " #test); \
message = test(); \
tests_run++; \
if (message) return message; \
} while(0)
#define RUN_TESTS(name) \
int main(int argc, char *argv[]) { \
(void) argc; \
tests_run = 0; \
printf("----\nRUNNING: %s\n", argv[0]); \
char *result = name(); \
if (result != 0) printf("\nFAILED: %s\n", result); \
else printf("\nALL TESTS PASSED\n"); \
printf("Tests run: %d\n", tests_run); \
exit(result == 0 ? EXIT_SUCCESS : EXIT_FAILURE); \
}
int tests_run;
#endif /* MINUNIT_H */