1 #include <ccan/err/err.c>
2 #include <ccan/tap/tap.h>
11 #define BUFFER_MAX 1024
13 int main(int argc, char *argv[])
20 err_set_progname(argv[0]);
22 /* In case it only prints out the basename of argv[0]. */
23 base = strrchr(argv[0], '/');
29 /* Test err() in child */
33 char buffer[BUFFER_MAX+1];
39 for (i = 0; i < BUFFER_MAX; i++) {
40 if (read(pfd[0], buffer + i, 1) == 0) {
42 ok1(strstr(buffer, "running err:"));
43 ok1(strstr(buffer, strerror(ENOENT)));
44 ok1(strstr(buffer, base));
45 ok1(buffer[i-1] == '\n');
50 ok1(wait(&status) != -1);
51 ok1(WIFEXITED(status));
52 ok1(WEXITSTATUS(status) == 17);
55 dup2(pfd[1], STDERR_FILENO);
57 err(17, "running %s", "err");
61 /* Test errx() in child */
65 char buffer[BUFFER_MAX+1];
71 for (i = 0; i < BUFFER_MAX; i++) {
72 if (read(pfd[0], buffer + i, 1) == 0) {
74 ok1(strstr(buffer, "running errx\n"));
75 ok1(strstr(buffer, base));
80 ok1(wait(&status) != -1);
81 ok1(WIFEXITED(status));
82 ok1(WEXITSTATUS(status) == 17);
85 dup2(pfd[1], STDERR_FILENO);
86 errx(17, "running %s", "errx");
91 /* Test warn() in child */
95 char buffer[BUFFER_MAX+1];
101 for (i = 0; i < BUFFER_MAX; i++) {
102 if (read(pfd[0], buffer + i, 1) == 0) {
104 ok1(strstr(buffer, "running warn:"));
105 ok1(strstr(buffer, strerror(ENOENT)));
106 ok1(strstr(buffer, base));
107 ok1(buffer[i-1] == '\n');
112 ok1(wait(&status) != -1);
113 ok1(WIFEXITED(status));
114 ok1(WEXITSTATUS(status) == 17);
117 dup2(pfd[1], STDERR_FILENO);
119 warn("running %s", "warn");
123 /* Test warnx() in child */
127 char buffer[BUFFER_MAX+1];
133 for (i = 0; i < BUFFER_MAX; i++) {
134 if (read(pfd[0], buffer + i, 1) == 0) {
136 ok1(strstr(buffer, "running warnx\n"));
137 ok1(strstr(buffer, base));
142 ok1(wait(&status) != -1);
143 ok1(WIFEXITED(status));
144 ok1(WEXITSTATUS(status) == 17);
147 dup2(pfd[1], STDERR_FILENO);
148 warnx("running %s", "warnx");
151 return exit_status();