1 /* We use the fact that pipes have a buffer greater than the size of
2 * any output, and change stdout and stderr to use that.
4 * Since we don't use libtap for output, this looks like one big test. */
15 /* We dup stderr to here. */
18 /* Simple replacement for err() */
19 static void failmsg(const char *fmt, ...)
24 /* Write into buffer. */
26 vsprintf(buf, fmt, ap);
29 write(stderrfd, "# ", 2);
30 write(stderrfd, buf, strlen(buf));
31 write(stderrfd, "\n", 1);
35 static void expect(int fd, const char *str)
37 char buffer[PIPE_BUF];
40 r = read(fd, buffer, sizeof(buffer));
42 failmsg("reading from pipe");
44 if (strlen(str) != r || strncmp(str, buffer, r) != 0)
45 failmsg("Expected '%s' got '%.*s'",
49 int main(int argc, char *argv[])
55 stderrfd = dup(STDERR_FILENO);
57 err(1, "dup of stderr failed");
59 stdoutfd = dup(STDOUT_FILENO);
61 err(1, "dup of stdout failed");
64 failmsg("pipe failed");
66 if (dup2(p[1], STDERR_FILENO) < 0 || dup2(p[1], STDOUT_FILENO) < 0)
67 failmsg("Duplicating file descriptor");
70 expect(p[0], "1..10\n");
73 expect(p[0], "ok 1 - msg1\n");
76 expect(p[0], "not ok 2 - msg2\n"
77 "# Failed test (tap/test/run.c:main() at line 75)\n");
80 expect(p[0], "ok 3 - true\n");
83 expect(p[0], "not ok 4 - false\n"
84 "# Failed test (tap/test/run.c:main() at line 82)\n");
87 expect(p[0], "ok 5 - passed\n");
90 expect(p[0], "not ok 6 - failed\n"
91 "# Failed test (tap/test/run.c:main() at line 89)\n");
93 skip(2, "skipping %s", "test");
94 expect(p[0], "ok 7 # skip skipping test\n"
95 "ok 8 # skip skipping test\n");
99 expect(p[0], "not ok 9 - false # TODO todo\n"
100 "# Failed (TODO) test (tap/test/run.c:main() at line 98)\n");
102 expect(p[0], "ok 10 - true # TODO todo\n");
105 if (exit_status() != 3)
106 failmsg("Expected exit status 3, not %i", exit_status());
109 /* Manually run the atexit command. */
111 expect(p[0], "# Looks like you failed 2 tests of 9.\n");
114 write(stdoutfd, "ok 1 - All passed\n", strlen("ok 1 - All passed\n"));