X-Git-Url: http://git.scottworley.com/tl-append/blobdiff_plain/27dfbfeb85b47cf506ebae0a760895dd43e2b62d..eaaa0046af50c3f918b95be93bfd4315b25690c0:/tl-append-test.c diff --git a/tl-append-test.c b/tl-append-test.c index 6761b02..3eef960 100644 --- a/tl-append-test.c +++ b/tl-append-test.c @@ -4,6 +4,17 @@ #include #include +struct expectation { + const char *message; +}; + +const struct expectation END = {NULL}; +static struct expectation expectation(const char *message) { + struct expectation exp; + exp.message = message; + return exp; +} + static void die(const char *message) { fputs(message, stderr); fputc('\n', stderr); @@ -23,7 +34,7 @@ static void remove_logfile() { } } -static void write_to_tl_append(const char *content) { +static struct expectation write_to_tl_append(const char *content) { FILE *p = popen("./tl-append", "w"); if (p == NULL) die_err("Couldn't run tl-append"); @@ -34,21 +45,24 @@ static void write_to_tl_append(const char *content) { die_err("Error closing pipe"); if (status != 0) die("tl-append exited abnormally"); + return expectation(content); } static void verify_log_contents(const char *contents) { - char buf[10]; + size_t len = strlen(contents); + char *buf = (char *)malloc(len + 2); FILE *f = fopen("tl.log", "r"); if (f == NULL) die_err("Error opening log file"); - buf[fread(buf, 1, sizeof(buf), f)] = '\0'; + buf[fread(buf, 1, len + 1, f)] = '\0'; if (ferror(f)) die("Error reading log file"); - if (strncmp(contents, buf, sizeof(buf)) != 0) + if (strncmp(contents, buf, len + 1) != 0) die("Wrong contents in log file"); if (fclose(f) != 0) die_err("Error closing log file"); + free(buf); } static void write_and_read_line() {