]> git.ozlabs.org Git - ccan/blobdiff - ccan/failtest/test/run-history.c
failtest: fix open in tests.
[ccan] / ccan / failtest / test / run-history.c
index 3b5220a518a803cbd0d8eb538e0932c1d153d653..88068b55eacdcec025fc6b21a1a9aa12fbfb343e 100644 (file)
@@ -2,52 +2,9 @@
 #include <stdio.h>
 #include <stdarg.h>
 #include <ccan/tap/tap.h>
-
-#define printf saved_printf
-static int saved_printf(const char *fmt, ...);
-
-#define fprintf saved_fprintf
-static int saved_fprintf(FILE *ignored, const char *fmt, ...);
-
 /* Include the C files directly. */
 #include <ccan/failtest/failtest.c>
 
-static char *output = NULL;
-
-static int saved_vprintf(const char *fmt, va_list ap)
-{
-       int ret = vsnprintf(NULL, 0, fmt, ap);
-       int len = 0;
-
-       if (output)
-               len = strlen(output);
-
-       output = realloc(output, len + ret + 1);
-       return vsprintf(output + len, fmt, ap);
-}
-
-static int saved_printf(const char *fmt, ...)
-{
-       va_list ap;
-       int ret;
-
-       va_start(ap, fmt);
-       ret = saved_vprintf(fmt, ap);
-       va_end(ap);
-       return ret;
-}      
-
-static int saved_fprintf(FILE *ignored, const char *fmt, ...)
-{
-       va_list ap;
-       int ret;
-
-       va_start(ap, fmt);
-       ret = saved_vprintf(fmt, ap);
-       va_end(ap);
-       return ret;
-}      
-
 int main(void)
 {
        struct failtest_call *call;
@@ -60,6 +17,7 @@ int main(void)
        struct write_call write_call;
        char buf[20];
        unsigned int i;
+       char *path;
 
        /* This is how many tests you plan to run */
        plan_tests(47);
@@ -87,8 +45,8 @@ int main(void)
        realloc_call.ret = realloc(malloc_call.ret, 3);
        realloc_call.ptr = malloc_call.ret;
        realloc_call.size = 3;
-       call = add_history(FAILTEST_REALLOC, "run-history.c",
-                          3, &realloc_call);
+       call = add_history(FAILTEST_REALLOC, "run-history.c", 3,
+                          &realloc_call);
        ok1(call->type == FAILTEST_REALLOC);
        ok1(strcmp(call->file, "run-history.c") == 0);
        ok1(call->line == 3);
@@ -96,8 +54,8 @@ int main(void)
        ok1(call->u.realloc.ptr == realloc_call.ptr);
        ok1(call->u.realloc.size == realloc_call.size);
 
-       open_call.ret = open("test/run_history.c", O_RDONLY);
-       open_call.pathname = "test/run_history.c";
+       open_call.ret = open("test/run-history.c", O_RDONLY);
+       open_call.pathname = "test/run-history.c";
        open_call.flags = O_RDONLY;
        open_call.mode = 0;
        call = add_history(FAILTEST_OPEN, "run-history.c", 4, &open_call);
@@ -144,23 +102,25 @@ int main(void)
        ok1(call->u.write.fd == write_call.fd);
        ok1(call->u.write.count == write_call.count);
 
-       ok1(history_num == 7);
+       i = 0;
+       tlist_for_each(&history, call, list)
+               i++;
+
+       ok1(i == 7);
 
-       for (i = 0; i < history_num; i++)
-               history[i].fail = false;
+       tlist_for_each(&history, call, list)
+               call->fail = false;
 
-       print_reproduce();
-       ok1(strcmp(output, "To reproduce: --failpath=cmeoprw\n") == 0);
-       free(output);
-       output = NULL;
+       path = failpath_string();
+       ok1(streq(path, "cmeoprw"));
+       free(path);
 
-       for (i = 0; i < history_num; i++)
-               history[i].fail = true;
+       tlist_for_each(&history, call, list)
+               call->fail = true;
 
-       print_reproduce();
-       ok1(strcmp(output, "To reproduce: --failpath=CMEOPRW\n") == 0);
-       free(output);
-       output = NULL;
+       path = failpath_string();
+       ok1(streq(path, "CMEOPRW"));
+       free(path);
 
        return exit_status();
 }