]> git.mdlowis.com Git - projs/tide.git/commitdiff
checked in beginnings of property based testing framework
authorMichael D. Lowis <mike@mdlowis.com>
Wed, 27 Feb 2019 04:03:09 +0000 (23:03 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Wed, 27 Feb 2019 04:03:09 +0000 (23:03 -0500)
Makefile
src/tide.c
tests/test_tide [new file with mode: 0755]
tests/test_tide.c [new file with mode: 0644]

index 0c7384f157f02b3038902cc4709deef74609c3c7..d7533211a0d62d31450d82e05367c128dbf16f62 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -13,8 +13,7 @@ LIBEDIT_OBJS = \
        src/lib/x11_gc.o \
        src/lib/x11_sel.o
 
-TEST_BINS = \
-       tests/libedit
+TEST_BINS =  tests/libedit tests/test_tide
 
 include config.mk
 
@@ -53,9 +52,13 @@ libedit.a: $(LIBEDIT_OBJS)
 
 tests/libedit: tests/libedit.o tests/lib/buf.o tests/lib/utf8.o libedit.a
 
-# define implicit rule for building binaries
+# define implicit rule for building normal binaries
 bin/%: src/%.o libedit.a
        $(LD) -o $@ $^ $(LDFLAGS)
 
+# define implicit rule for building tests binaries
+tests/%: tests/%.o libedit.a
+       $(LD) -o $@ $^ $(LDFLAGS)
+
 # load generate dependencies
 -include src/*.d src/lib/*.d tests/*.d tests/lib/*.d
index 8e07013294e31b241df64193eb20587dffd0b7b7..46c7249694ad223f15ef81fdf2f7b4da72733182 100644 (file)
 /* stub some functions for test so we don't interact with the outside world too much */
 #ifdef TEST
 #define job_start(cmd, data, ndata, dest) \
-    ((void)cmd, (void)data, (void)ndata, (void)dest)
-#define job_run(char** cmd)
-    ((void)cmd, 0)
-#define x11_sel_get(x, selid, str) \
-    ((void)x, (void)selid, (void)str)
+    ((void)(cmd), (void)(data), (void)(ndata), (void)(dest))
+#define job_run(cmd) \
+    ((void)(cmd), 0)
+#define x11_sel_set(x, selid, str) \
+    ((void)(x), (void)(selid), (void)(str))
 #define x11_sel_get(x, selid, cbfn) \
-    ((void)x, (void)selid, (void)cbfn, (void)1)
+    ((void)(x), (void)(selid), (void)(cbfn), 1)
 #endif
 
 /* predeclare some things */
diff --git a/tests/test_tide b/tests/test_tide
new file mode 100755 (executable)
index 0000000..8098b76
Binary files /dev/null and b/tests/test_tide differ
diff --git a/tests/test_tide.c b/tests/test_tide.c
new file mode 100644 (file)
index 0000000..fd04b69
--- /dev/null
@@ -0,0 +1,87 @@
+#include <time.h>
+
+#define TEST
+#include "src/tide.c"
+
+typedef struct {
+  void *value;
+  int nelem;
+//  QCC_showValue show;
+//  QCC_freeValue free;
+} QCValue;
+
+typedef struct {
+    int status, nvals;
+    QCValue** vals;
+} QCResult;
+
+typedef int (*QCProp)(QCValue** vals, int nvals);
+
+typedef QCValue* (*QCGenFn)(void);
+
+
+
+
+void qc_init(int seed) {
+    srand(seed ? seed : time(NULL));
+}
+
+QCResult vforAll(QCProp prop, int nvals, va_list vals) {
+    /* generate the input values */
+    QCValue** values = NULL;
+    if (nvals) {
+        values = malloc(sizeof(QCValue*) * nvals);
+        for (int i = 0; i < nvals; i++)
+            values[i] = (va_arg(vals, QCGenFn))();
+    }
+    /* run the test and get the result */
+    QCResult result = { .status = 0 };
+    result.status = prop(values, nvals);
+    result.nvals = nvals;
+    result.vals = values;
+    return result;
+}
+
+int forAll(int num, QCProp prop, int nvals, ...) {
+    (void)num, (void)prop, (void)nvals;
+    int passed = 0;
+    QCResult result;
+    va_list vals;
+    for (int i = 0; i < num; i++) {
+        va_start(vals, nvals);
+        result = vforAll(prop, nvals, vals);
+        va_end(vals);
+        if (!result.status) break;
+        passed++;
+    }
+    /* show 'em the results */
+    if (passed == num) {
+        printf("%d tests passed\n", passed);
+    } else if (result.status == 0) {
+        printf("Falsifiable after %d tests\n", passed+1);
+        return 0;
+    }
+    return 1;
+}
+
+/************************************************/
+
+void tide_init(void) {
+    if (!ShellCmd[0]) ShellCmd[0] = getenv("SHELL");
+    if (!ShellCmd[0]) ShellCmd[0] = "/bin/sh";
+    win_init(Bindings);
+    view_init(&Regions[TAGS], NULL);
+    view_init(&Regions[EDIT], NULL);
+    view_putstr(win_view(TAGS), TagString);
+    view_resize(win_view(TAGS), 640, 1);
+    buf_logclear(win_buf(TAGS));
+    win_prop_set("TIDE", "", "tide");
+    xupdate(NULL);
+}
+
+
+int main(int argc, char** argv) {
+    (void)argc, (void)argv, (void)usage;
+    puts("running prop tests");
+    return 0;
+}