From: Michael D. Lowis Date: Wed, 27 Feb 2019 04:03:09 +0000 (-0500) Subject: checked in beginnings of property based testing framework X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=f255bb945d85e00305ddf445e206066d1d9cb79a;p=projs%2Ftide.git checked in beginnings of property based testing framework --- diff --git a/Makefile b/Makefile index 0c7384f..d753321 100644 --- 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 diff --git a/src/tide.c b/src/tide.c index 8e07013..46c7249 100644 --- a/src/tide.c +++ b/src/tide.c @@ -13,13 +13,13 @@ /* 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 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 index 0000000..fd04b69 --- /dev/null +++ b/tests/test_tide.c @@ -0,0 +1,87 @@ +#include + +#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; +}