X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=t%2Fctap%2Fprove.c;h=7d1b8e2eaa37b172bf95240e26b3869017e3db0d;hb=b120452a12d0ffef68822f8a83f67ab89c606a08;hp=8ff8a6410ded3fb02a77bee17e1ad5aa3d30c853;hpb=4bcba29f166e9a93c109a43c68c20d630f2c2465;p=zpackage diff --git a/t/ctap/prove.c b/t/ctap/prove.c index 8ff8a64..7d1b8e2 100644 --- a/t/ctap/prove.c +++ b/t/ctap/prove.c @@ -11,6 +11,7 @@ #include #define GREATER(x,y) ( ((x) > (y)) ? (x) : (y) ) +#define WARN(x) fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, x) struct result { int test; /* i.e. the number of the test */ @@ -21,6 +22,7 @@ struct result { struct testrun { char *name; + int readstdin; int version; int plan; int ran; @@ -55,43 +57,51 @@ int runone(struct testrun *run) { int pipefd[2]; pid_t cpid; FILE *tap; - char *line; + char *line = 0; ssize_t nread; size_t len = 0; int written = 0; - if (pipe(pipefd) == -1) { - perror("pipe"); - exit(EXIT_FAILURE); - } - - cpid = fork(); - if (cpid == -1) { - perror("fork"); - exit(EXIT_FAILURE); - } + if (!run->readstdin) { + if (pipe(pipefd) == -1) { + perror("pipe"); + exit(EXIT_FAILURE); + } - if (cpid == 0) { - /* child */ - close(pipefd[0]); /* close read end */ - close(1); /* close stdout */ - dup(pipefd[1]); /* set stdout to the write end of the pipe */ - execlp(run->name, run->name, NULL); - /* only gets here if exec failed */ - printf("Bail Out! exec %s failed: %s\n", run->name, strerror(errno)); - exit(EXIT_FAILURE); - } + cpid = fork(); + if (cpid == -1) { + perror("fork"); + exit(EXIT_FAILURE); + } + + if (cpid == 0) { + /* child */ + close(pipefd[0]); /* close read end */ + close(1); /* close stdout */ + dup(pipefd[1]); /* set stdout to the write end of the pipe */ + execlp(run->name, run->name, NULL); + /* only gets here if exec failed */ + printf("Bail Out! exec %s failed: %s\n", run->name, strerror(errno)); + exit(EXIT_FAILURE); + } - close(pipefd[1]); - /* parent continue on */ - tap = fdopen(pipefd[0], "r"); + close(pipefd[1]); + /* parent continue on */ + tap = fdopen(pipefd[0], "r"); + if (tap == NULL) { + perror("tap is null:"); + exit(EXIT_FAILURE); + } + } else { + tap = stdin; + } regex_t plan, diagnostic, bail, test, directive, version; regmatch_t match[4]; regcomp(&plan, "^[[:digit:]]+\\.\\.([[:digit:]]+)", REG_EXTENDED); regcomp(&diagnostic, "#[[:space:]]*(.+)", REG_EXTENDED); - regcomp(&bail, "^Bail Out![[:space:]]*(.+)", REG_EXTENDED); + regcomp(&bail, "^Bail Out![[:space:]]*(.+)", REG_EXTENDED|REG_ICASE); regcomp(&version, "^TAP Version ([[:digit:]]+)", REG_EXTENDED); regcomp(&test, "^(not )?ok([[:space:]]*([[:digit:]]+))?", REG_EXTENDED); @@ -218,7 +228,9 @@ int runone(struct testrun *run) { regfree(&test); free(line); - fclose(tap); + if (!run->readstdin) { + fclose(tap); + } wait(NULL); if (run->ran < run->plan) { @@ -251,6 +263,8 @@ int main(int ac, char *av[]) { struct testrun clear = { 0 }; struct testrun *runs; int opt; + char *stdinname = ""; + int stdinnamelen = 0; /* * -j json output @@ -266,7 +280,7 @@ int main(int ac, char *av[]) { /* TODO -jj turn off everything else? */ /* TODO -cC color escapes */ - while ((opt = getopt(ac, av, "jJpPiIsSdD")) != -1) { + while ((opt = getopt(ac, av, "jJpPiIsSdDn:")) != -1) { switch (opt) { case 'j': json = 1; break; case 'J': json = 0; break; @@ -278,25 +292,39 @@ int main(int ac, char *av[]) { case 'S': summary = 0; break; case 'd': detail = 1; break; case 'D': detail = 0; break; + case 'n': stdinname = optarg; + break; default: /* '?' */ fprintf(stderr, "Usage: %s [-jpisd] file...\n", av[0]); exit(EXIT_FAILURE); } } + stdinnamelen = strlen(stdinname); runs = malloc(ac * sizeof *runs); for (i=optind; i