1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4
5
6 static int succeeded;
7 static int failed;
8 static bool verbose;
9
log_test(bool predicate,const char * file,int line,const char * message)10 void log_test(bool predicate, const char *file, int line, const char *message)
11 {
12 if (predicate)
13 {
14 if (verbose)
15 {
16 printf("Test passed: %s:%d: %s\n", file, line, message);
17 }
18 succeeded++;
19 return;
20 }
21 failed++;
22 printf("Test failed: %s:%d: %s\n", file, line, message);
23 }
24
log_totals(void)25 static void log_totals(void)
26 {
27 printf("\n%d tests, %d passed, %d failed\n", succeeded+failed, succeeded, failed);
28 }
29
init(void)30 static void __attribute__((constructor)) init(void)
31 {
32 atexit(log_totals);
33 }
34
35 void test_type_info(void);
36 void test_exceptions();
37 void test_guards(void);
main(int argc,char ** argv)38 int main(int argc, char **argv)
39 {
40 int ch;
41
42 while ((ch = getopt(argc, argv, "v")) != -1)
43 {
44 switch (ch)
45 {
46 case 'v':
47 verbose = true;
48 default: break;
49 }
50 }
51
52 test_type_info();
53 test_guards();
54 test_exceptions();
55 return 0;
56 }
57