]> git.scottworley.com Git - tl-append/blame - tl-append-test.c
Begin
[tl-append] / tl-append-test.c
CommitLineData
b3d5ed96
SW
1#define _POSIX_C_SOURCE 2
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5
6static void die(const char *message) {
7 fputs(message, stderr);
8 fputc('\n', stderr);
9 exit(1);
10}
11
12static void die_err(const char *message) {
13 perror(message);
14 exit(1);
15}
16
17static void write_and_read_line() {
18 char buf[10];
19
20 FILE *p = popen("./tl-append", "w");
21 if (p == NULL)
22 die_err("Couldn't run tl-append");
23 if (fputs("foo\n", p) == EOF)
24 die("Couldn't write to pipe");
25 int status = pclose(p);
26 if (status < 0)
27 die_err("Error closing pipe");
28 if (status != 0)
29 die("tl-append exited abnormally");
30
31 FILE *f = fopen("tl.log", "r");
32 if (f == NULL)
33 die_err("Error opening log file");
34 if (fgets(buf, sizeof(buf), f) == NULL)
35 die("Error reading log file");
36 if (strncmp("foo\n", buf, sizeof(buf)) != 0)
37 die("Wrong contents in log file");
38 if (fclose(f) != 0)
39 die_err("Error closing log file");
40}
41
42int main() { write_and_read_line(); }