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. */
16 /* We dup stderr to here. */
19 /* Simple replacement for err() */
20 static void failmsg(const char *fmt, ...)
25 /* Write into buffer. */
27 vsprintf(buf, fmt, ap);
30 write(stderrfd, "# ", 2);
31 write(stderrfd, buf, strlen(buf));
32 write(stderrfd, "\n", 1);
36 static void expect(int fd, const char *pattern)
38 char buffer[PIPE_BUF+1];
41 r = read(fd, buffer, sizeof(buffer)-1);
43 failmsg("reading from pipe");
46 if (fnmatch(pattern, buffer, 0) != 0)
47 failmsg("Expected '%s' got '%s'", pattern, buffer);
50 int main(int argc, char *argv[])
57 stderrfd = dup(STDERR_FILENO);
59 err(1, "dup of stderr failed");
61 stdoutfd = dup(STDOUT_FILENO);
63 err(1, "dup of stdout failed");
66 failmsg("pipe failed");
68 if (dup2(p[1], STDERR_FILENO) < 0 || dup2(p[1], STDOUT_FILENO) < 0)
69 failmsg("Duplicating file descriptor");
72 expect(p[0], "1..10\n");
75 expect(p[0], "ok 1 - msg1\n");
78 expect(p[0], "not ok 2 - msg2\n"
79 "# Failed test (*tap/test/run.c:main() at line 77)\n");
82 expect(p[0], "ok 3 - true\n");
85 expect(p[0], "not ok 4 - false\n"
86 "# Failed test (*tap/test/run.c:main() at line 84)\n");
89 expect(p[0], "ok 5 - passed\n");
92 expect(p[0], "not ok 6 - failed\n"
93 "# Failed test (*tap/test/run.c:main() at line 91)\n");
95 skip(2, "skipping %s", "test");
96 expect(p[0], "ok 7 # skip skipping test\n"
97 "ok 8 # skip skipping test\n");
101 expect(p[0], "not ok 9 - false # TODO todo\n"
102 "# Failed (TODO) test (*tap/test/run.c:main() at line 100)\n");
104 expect(p[0], "ok 10 - true # TODO todo\n");
107 if (exit_status() != 3)
108 failmsg("Expected exit status 3, not %i", exit_status());
111 /* Manually run the atexit command. */
113 expect(p[0], "# Looks like you failed 2 tests of 9.\n");
116 write(stdoutfd, "ok 1 - All passed\n", strlen("ok 1 - All passed\n"));