X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftap%2Ftest%2Frun.c;h=efc8134dcbd273edd34a8269220486ada6dbc278;hp=2f718cc27fbbf0e6c8e7fb61de6d114bf42141b7;hb=c4c5fed020ba44b9930119672a36a1cb33aff090;hpb=650c775ff00cccd03fc84e7789a03c51d9839004 diff --git a/ccan/tap/test/run.c b/ccan/tap/test/run.c index 2f718cc2..efc8134d 100644 --- a/ccan/tap/test/run.c +++ b/ccan/tap/test/run.c @@ -2,20 +2,34 @@ * any output, and change stdout and stderr to use that. * * Since we don't use libtap for output, this looks like one big test. */ -#include "tap/tap.h" +#include +#include #include -#include -#include +#include #include #include -#include -#include #include #include + + /* We dup stderr to here. */ static int stderrfd; +/* write_all inlined here to avoid circular dependency. */ +static void write_all(int fd, const void *data, size_t size) +{ + while (size) { + ssize_t done; + + done = write(fd, data, size); + if (done <= 0) + _exit(1); + data += done; + size -= done; + } +} + /* Simple replacement for err() */ static void failmsg(const char *fmt, ...) { @@ -27,9 +41,9 @@ static void failmsg(const char *fmt, ...) vsprintf(buf, fmt, ap); va_end(ap); - write(stderrfd, "# ", 2); - write(stderrfd, buf, strlen(buf)); - write(stderrfd, "\n", 1); + write_all(stderrfd, "# ", 2); + write_all(stderrfd, buf, strlen(buf)); + write_all(stderrfd, "\n", 1); _exit(1); } @@ -76,21 +90,21 @@ int main(int argc, char *argv[]) ok(0, "msg2"); expect(p[0], "not ok 2 - msg2\n" - "# Failed test (*tap/test/run.c:main() at line 77)\n"); + "# Failed test (*test/run.c:main() at line 91)\n"); ok1(true); expect(p[0], "ok 3 - true\n"); ok1(false); expect(p[0], "not ok 4 - false\n" - "# Failed test (*tap/test/run.c:main() at line 84)\n"); + "# Failed test (*test/run.c:main() at line 98)\n"); pass("passed"); expect(p[0], "ok 5 - passed\n"); fail("failed"); expect(p[0], "not ok 6 - failed\n" - "# Failed test (*tap/test/run.c:main() at line 91)\n"); + "# Failed test (*test/run.c:main() at line 105)\n"); skip(2, "skipping %s", "test"); expect(p[0], "ok 7 # skip skipping test\n" @@ -99,7 +113,7 @@ int main(int argc, char *argv[]) todo_start("todo"); ok1(false); expect(p[0], "not ok 9 - false # TODO todo\n" - "# Failed (TODO) test (*tap/test/run.c:main() at line 100)\n"); + "# Failed (TODO) test (*test/run.c:main() at line 114)\n"); ok1(true); expect(p[0], "ok 10 - true # TODO todo\n"); todo_end(); @@ -113,6 +127,7 @@ int main(int argc, char *argv[]) expect(p[0], "# Looks like you failed 2 tests of 9.\n"); #endif - write(stdoutfd, "ok 1 - All passed\n", strlen("ok 1 - All passed\n")); - _exit(0); + write_all(stdoutfd, "ok 1 - All passed\n", + strlen("ok 1 - All passed\n")); + exit(0); }