X-Git-Url: http://git.scottworley.com/tl-append/blobdiff_plain/853b83c48d322e84bc1fffa80255180223cf8aad..d522116b5fdc09e3f83fe4f88515dec52a3e0462:/tl-append-test.c?ds=sidebyside diff --git a/tl-append-test.c b/tl-append-test.c index 3ac174c..6d037cb 100644 --- a/tl-append-test.c +++ b/tl-append-test.c @@ -5,6 +5,8 @@ #include #include +#include "common.h" + typedef struct expectation { time_t a, b; const char *message; @@ -22,19 +24,8 @@ static ex_t expectation(time_t a, time_t b, const char *message) { return exp; } -static void die(const char *message) { - fputs(message, stderr); - fputc('\n', stderr); - exit(1); -} - -static void die_err(const char *message) { - perror(message); - exit(1); -} - static void remove_logfile() { - if (remove("tl.log") != 0) { + if (remove(FILENAME) != 0) { if (errno != ENOENT) { die_err("Error removing log file"); } @@ -45,19 +36,21 @@ static ex_t write_to_tl_append(const char *content) { FILE *p = popen("./tl-append", "w"); if (p == NULL) die_err("Couldn't run tl-append"); + time_t start = time(NULL); if (fputs(content, p) == EOF) die("Couldn't write to pipe"); int status = pclose(p); + time_t end = time(NULL); if (status < 0) die_err("Error closing pipe"); if (status != 0) die("tl-append exited abnormally"); - return expectation((time_t)-1, ((time_t)-1), content); + return expectation(start, end, content); } static void verify_log_contents(ex_t exps[]) { - FILE *f = fopen("tl.log", "r"); + FILE *f = fopen(FILENAME, "r"); if (f == NULL) die_err("Error opening log file"); for (size_t i = 0; !is_end(exps[i]); i++) {