struct testrun {
char *name;
+ int readstdin;
int version;
int plan;
int ran;
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];
regfree(&test);
free(line);
- fclose(tap);
+ if (!run->readstdin) {
+ fclose(tap);
+ }
wait(NULL);
if (run->ran < run->plan) {
struct testrun clear = { 0 };
struct testrun *runs;
int opt;
+ char *stdinname = "<stdin>";
+ int stdinnamelen = 0;
/*
* -j json output
/* 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;
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<ac; i++) {
- len = strlen(av[i]);
- maxnamelen = GREATER(len, maxnamelen);
+ if (!strcmp(av[i], "-")) {
+ maxnamelen = GREATER(stdinnamelen, maxnamelen);
+ } else {
+ len = strlen(av[i]);
+ maxnamelen = GREATER(len, maxnamelen);
+ }
}
for (i=optind; i<ac; i++) {
run = clear;
- run.name = av[i];
run.interactive = interactive;
+ if (!strcmp(av[i], "-")) {
+ run.readstdin = 1;
+ run.name = stdinname;
+ } else {
+ run.readstdin = 0;
+ run.name = av[i];
+ }
+
if (progress) {
printf("%s ", run.name);
len = strlen(run.name);