From: Nathan Wagner Date: Tue, 21 Aug 2018 11:20:40 +0000 (+0000) Subject: have ctap prove read from stdin X-Git-Tag: v0.1.6~62 X-Git-Url: https://pd.if.org/git/?p=zpackage;a=commitdiff_plain;h=dc08462c5c1d2cb9ae52a7b1df98603cb1160262 have ctap prove read from stdin --- diff --git a/t/ctap/prove.c b/t/ctap/prove.c index 8ff8a64..1d87035 100644 --- a/t/ctap/prove.c +++ b/t/ctap/prove.c @@ -21,6 +21,7 @@ struct result { struct testrun { char *name; + int readstdin; int version; int plan; int ran; @@ -60,31 +61,35 @@ int runone(struct testrun *run) { 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); + } - close(pipefd[1]); - /* parent continue on */ - tap = fdopen(pipefd[0], "r"); + 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"); + } else { + tap = stdin; + } regex_t plan, diagnostic, bail, test, directive, version; regmatch_t match[4]; @@ -218,7 +223,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 +258,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 +275,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 +287,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