chiark / gitweb /
@@@ tvec and tty mess
[mLib] / utils / t / exc-test.c
index 89701bfd223b66580e69901bf450fa38aa61acd7..69fa8cdb26d60bb7901f2e94f54d65938501fb63 100644 (file)
@@ -1,44 +1,65 @@
 #include <stdio.h>
+
 #include "exc.h"
+#include "macros.h"
+#include "report.h"
+#include "tvec.h"
+#include "tvec-adhoc.h"
+#include "tvec-types.h"
+
+static struct tvec_state tvstate;
+static int step;
 
-void func(void)
+#define TESTGROUP(name)                                                        \
+       TVEC_TESTGROUP_TAG(grp, &tvstate, name)                         \
+       MC_BEFORE(init, { step = 0; })
+#define TEST TVEC_TEST_TAG(test, &tvstate)
+#define STEP(s) do {                                                   \
+         tvec_claim(&tvstate, s == step, __FILE__, __LINE__,           \
+                    "found %d /= expected %d", s, step);               \
+         step++;                                                       \
+       } while (0)
+#define MISSTEP do {                                                   \
+         tvec_claim(&tvstate, 0, __FILE__, __LINE__,                   \
+                    "shouldn't have reached here");                    \
+         step++;                                                       \
+       } while (0)
+
+static void func(void)
 {
-  printf("cabbage\n");
-  TRY {
-    printf("dibble\n");
-    THROW(EXC_FAIL, "excession");
-    printf("can't see me\n");
-  } CATCH switch (exc_type) {
-    case 1:
-      printf("exc type 1 (not possible)\n");
-      break;
-    case EXC_FAIL:
-      printf("exc type 2 (%s)\n", exc_s);
-      break;
-    default:
-      RETHROW;
+  TRY { STEP(2); THROW(EXC_FAIL, "excession"); MISSTEP; }
+  CATCH switch (exc_type) {
+    case EXC_FAIL: TVEC_CLAIMEQ_TEXTZ(&tvstate, exc_s, "excession"); break;
+    default: MISSTEP; break;
   } END_TRY;
 
-  printf("fennel\n");
-  THROW(EXC_ERRNO, 53);
+  TRY { STEP(3); THROW(EXC_ERRNO, 53); }
+  CATCH switch (exc_type) {
+    case EXC_ERRNO: RETHROW;
+    default: MISSTEP; break;
+  } END_TRY;
+  MISSTEP;
 }
 
-int main(void)
+int main(int argc, char *argv[])
 {
-  printf("apple\n");
-  TRY {
-    printf("banana\n");
-    func();
-    printf("can't see me\n");
-  } CATCH switch (exc_type) {
-    default:
-      printf("%lu exception (val = %i)\n", exc_type, exc_i);
-      break;
-  } END_TRY;
-  printf("hello! __exc_list = ");
-  if (__exc_list) printf("%p", (void *)__exc_list);
-  else printf("(nil)");
-  putchar('\n');
+  int argpos;
+
+  tvec_parseargs(argc, argv, &tvstate, &argpos, &tvec_adhocconfig);
+  if (argpos < argc) die(2, "no input files expected");
+
+  TESTGROUP("flow") {
+    STEP(0);
+    TRY { STEP(1); func(); MISSTEP; }
+    CATCH switch (exc_type) {
+      case EXC_ERRNO: STEP(4); TVEC_CLAIMEQ_INT(&tvstate, exc_i, 53); break;
+      default: MISSTEP;
+    } END_TRY;
+    STEP(5);
+  }
+
+  TESTGROUP("final")
+    TVEC_CLAIMEQ_PTR(&tvstate, __exc_list, 0);
 
-  return (0);
+  return (tvec_end(&tvstate));
 }