]> git.scottworley.com Git - tl-append/commitdiff
Refactor test
authorScott Worley <scottworley@scottworley.com>
Thu, 31 Aug 2023 17:46:45 +0000 (10:46 -0700)
committerScott Worley <scottworley@scottworley.com>
Fri, 1 Sep 2023 07:39:16 +0000 (00:39 -0700)
tl-append-test.c

index be2adcb09403e6e1ba4a69d419765ef9e5dfcfa7..0867280d26afc5a843c21c7e5eeaf576cd5f85f9 100644 (file)
@@ -14,29 +14,36 @@ static void die_err(const char *message) {
   exit(1);
 }
 
-static void write_and_read_line() {
-  char buf[10];
-
+static void write_to_tl_append(const char *content) {
   FILE *p = popen("./tl-append", "w");
   if (p == NULL)
     die_err("Couldn't run tl-append");
-  if (fputs("foo\n", p) == EOF)
+  if (fputs(content, p) == EOF)
     die("Couldn't write to pipe");
   int status = pclose(p);
   if (status < 0)
     die_err("Error closing pipe");
   if (status != 0)
     die("tl-append exited abnormally");
+}
+
+static void verify_log_contents(const char *contents) {
+  char buf[10];
 
   FILE *f = fopen("tl.log", "r");
   if (f == NULL)
     die_err("Error opening log file");
   if (fgets(buf, sizeof(buf), f) == NULL)
     die("Error reading log file");
-  if (strncmp("foo\n", buf, sizeof(buf)) != 0)
+  if (strncmp(contents, buf, sizeof(buf)) != 0)
     die("Wrong contents in log file");
   if (fclose(f) != 0)
     die_err("Error closing log file");
 }
 
+static void write_and_read_line() {
+  write_to_tl_append("foo\n");
+  verify_log_contents("foo\n");
+}
+
 int main() { write_and_read_line(); }