Add Glk unit test framework
[projects/chimara/chimara.git] / tests / unit / glkunit.c
diff --git a/tests/unit/glkunit.c b/tests/unit/glkunit.c
new file mode 100644 (file)
index 0000000..63d8134
--- /dev/null
@@ -0,0 +1,28 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "glk.h"
+#include "glkunit.h"
+
+extern struct TestDescription tests[];
+
+void
+glk_main(void)
+{
+    struct TestDescription *test = tests;
+    int tested = 0, succeeded = 0, failed = 0;
+    while(test->name != NULL) {
+        tested++;
+        /* Use stdio.h to print to stdout, Glk can't do that */
+        printf("  Testing %s... ", test->name);
+        if( test->testfunc() ) {
+            succeeded++;
+            printf("PASS\n");
+        } else {
+            failed++;
+            printf("FAIL\n");
+        }
+        test++;
+    }
+    printf("%d tests run, %d failures\n", tested, failed);
+    exit(failed > 0);
+}