+#define _POSIX_C_SOURCE 200809L
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <strings.h>
#include <unistd.h>
+#include <errno.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <regex.h>
int pipefd[2];
pid_t cpid;
FILE *tap;
- char *line;
- size_t nread, len = 0;
+ char *line = 0;
+ ssize_t nread;
+ size_t len = 0;
int written = 0;
if (pipe(pipefd) == -1) {
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]);
int skip = 0;
int pass = 0;
+ run->ran++;
+
+ if (run->interactive) {
+ backup(written);
+ written = printf("%d/%d", run->ran, run->plan);
+ fflush(stdout);
+ }
+
+
/* if the "not" match fails, the test passed */
pass = match[1].rm_so == -1;
}
/* check for diagnostics */
- if (test != run->ran+1) {
+ if (test != run->ran) {
fprintf(stderr, "expected test %d, got %d\n", run->ran+1, test);
}
- run->ran++;
-
- if (pass || todo) {
+ /* pass, todo, or skip are all pass */
+ if (pass || todo || skip) {
run->pass++;
+ } else {
+ run->fail++;
}
- if (todo) {
- if (pass) {
- run->todo_pass++;
- }
+ if (todo && pass) {
+ run->todo_pass++;
}
+
if (skip) {
run->skip++;
}
- if (!pass) {
+ if (!pass && !todo) {
struct result *r;
r = malloc(sizeof *r);
/* push test number onto fail list */
}
- if (run->interactive) {
- backup(written);
- written = printf("%d/%d", run->ran, run->plan);
- fflush(stdout);
- }
}
else if (rmatch(&diagnostic, line, match)) {
}
void json(struct testrun *total, struct testrun *runs, int nruns) {
-
+ if (total && runs && nruns) {
+ return;
+ }
+ return;
}
int main(int ac, char *av[]) {
for (i=optind; i<ac; i++) {
run = clear;
run.name = av[i];
- run.plan = -1;
run.interactive = interactive;
if (progress) {
total.ran += run.ran;
total.pass += run.pass;
total.fail += run.fail;
+ total.skip += run.skip;
if (progress) {
- if (run.fail > 0 ) printf("not ");
- printf("ok\n");
+ if (run.bailout) {
+ printf("Bail out!\n");
+ } else {
+ if (run.fail > 0 ) printf("not ");
+ printf("ok\n");
+ }
}
runs[i-optind] = run;
}
if (summary) {
- printf("ran: %d/%d, pass: %d, fail: %d, %.2f%% ok\n",
+ printf("ran: %d/%d, pass: %d, fail: %d, skip: %d",
total.ran, total.plan, total.pass, total.fail,
- 100.0*(double)total.pass/(double)total.plan
+ total.skip
);
+ if (total.plan > 0) {
+ printf(", %.2f%% ok",
+ 100.0*(double)total.pass/(double)total.plan
+ );
+ }
+ printf("\n");
}