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[])
56 stderrfd = dup(STDERR_FILENO);
58 err(1, "dup of stderr failed");
60 stdoutfd = dup(STDOUT_FILENO);
62 err(1, "dup of stdout failed");
65 failmsg("pipe failed");
67 if (dup2(p[1], STDERR_FILENO) < 0 || dup2(p[1], STDOUT_FILENO) < 0)
68 failmsg("Duplicating file descriptor");
71 expect(p[0], "1..10\n");
74 expect(p[0], "ok 1 - msg1\n");
77 expect(p[0], "not ok 2 - msg2\n"
78 "# Failed test (tap/test/run.c:main() at line 76)\n");
81 expect(p[0], "ok 3 - true\n");
84 expect(p[0], "not ok 4 - false\n"
85 "# Failed test (tap/test/run.c:main() at line 83)\n");
88 expect(p[0], "ok 5 - passed\n");
91 expect(p[0], "not ok 6 - failed\n"
92 "# Failed test (tap/test/run.c:main() at line 90)\n");
94 skip(2, "skipping %s", "test");
95 expect(p[0], "ok 7 # skip skipping test\n"
96 "ok 8 # skip skipping test\n");
100 expect(p[0], "not ok 9 - false # TODO todo\n"
101 "# Failed (TODO) test (tap/test/run.c:main() at line 99)\n");
103 expect(p[0], "ok 10 - true # TODO todo\n");
106 if (exit_status() != 3)
107 failmsg("Expected exit status 3, not %i", exit_status());
110 /* Manually run the atexit command. */
112 expect(p[0], "# Looks like you failed 2 tests of 9.\n");
115 write(stdoutfd, "ok 1 - All passed\n", strlen("ok 1 - All passed\n"));