]>
git.scottworley.com Git - tl-append/blob - tl-append-test.c
1 #define _POSIX_C_SOURCE 2
6 static void die(const char *message
) {
7 fputs(message
, stderr
);
12 static void die_err(const char *message
) {
17 static void write_to_tl_append(const char *content
) {
18 FILE *p
= popen("./tl-append", "w");
20 die_err("Couldn't run tl-append");
21 if (fputs(content
, p
) == EOF
)
22 die("Couldn't write to pipe");
23 int status
= pclose(p
);
25 die_err("Error closing pipe");
27 die("tl-append exited abnormally");
30 static void verify_log_contents(const char *contents
) {
33 FILE *f
= fopen("tl.log", "r");
35 die_err("Error opening log file");
36 if (fgets(buf
, sizeof(buf
), f
) == NULL
)
37 die("Error reading log file");
38 if (strncmp(contents
, buf
, sizeof(buf
)) != 0)
39 die("Wrong contents in log file");
41 die_err("Error closing log file");
44 static void write_and_read_line() {
45 write_to_tl_append("foo\n");
46 verify_log_contents("foo\n");
49 int main() { write_and_read_line(); }