Add Glk unit test framework
[projects/chimara/chimara.git] / tests / unit / glkunit.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "glk.h"
4 #include "glkunit.h"
5
6 extern struct TestDescription tests[];
7
8 void
9 glk_main(void)
10 {
11     struct TestDescription *test = tests;
12     int tested = 0, succeeded = 0, failed = 0;
13     while(test->name != NULL) {
14         tested++;
15         /* Use stdio.h to print to stdout, Glk can't do that */
16         printf("  Testing %s... ", test->name);
17         if( test->testfunc() ) {
18             succeeded++;
19             printf("PASS\n");
20         } else {
21             failed++;
22             printf("FAIL\n");
23         }
24         test++;
25     }
26     printf("%d tests run, %d failures\n", tested, failed);
27     exit(failed > 0);
28 }