Commit Diff


commit - 30d22cc724c2dab1c94046e33c729ed24f591b94
commit + 32b8add4cfa7e7c66ac6be38b2cc956880dde08c
blob - e1ef5a0a9c9724f8f4ce816d6a4aee0e4605678d
blob + 2df71001f2c0ddff2c4217feba1820fecb17df36
--- ninepscript.8
+++ ninepscript.8
@@ -21,6 +21,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl nv
+.Op Fl x Ar pattern
 .Ar
 .Sh DESCRIPTION
 .Nm
@@ -38,6 +39,9 @@ don't run the test, check only the syntax of the provi
 .Ar files .
 .It Fl v
 verbose logging, print more information during the tests execution.
+.It Fl x Ar pattern
+Run only the tests that match the given
+.Ar pattern .
 .El
 .Pp
 .Nm
blob - 98be0d4eafb875d187341dd0b173b3f0fc039e03
blob + 4fb5bc0910430077c25c774212922762678ad98f
--- script.c
+++ script.c
@@ -27,6 +27,7 @@
 #include <inttypes.h>
 #include <poll.h>
 #include <pwd.h>
+#include <regex.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -1620,6 +1621,8 @@ main(int argc, char **argv)
 	struct test	*t;
 	int		 ch, i, r, passed = 0, failed = 0, skipped = 0;
 	int		 runclient = 0;
+	const char	*pat = NULL;
+	regex_t		 reg;
 
 	assert(argv0 = argv[0]);
 
@@ -1638,7 +1641,7 @@ main(int argc, char **argv)
 	add_builtin_proc("send", builtin_send, 2, 1);
 	add_builtin_proc("recv", builtin_recv, 0, 0);
 
-	while ((ch = getopt(argc, argv, "nT:v")) != -1) {
+	while ((ch = getopt(argc, argv, "nT:vx:")) != -1) {
 		switch (ch) {
 		case 'n':
 			syntaxcheck = 1;
@@ -1650,6 +1653,9 @@ main(int argc, char **argv)
 		case 'v':
 			debug = 1;
 			break;
+		case 'x':
+			pat = optarg;
+			break;
 		default:
 			fprintf(stderr, "Usage: %s [-nv] [files...]\n",
 			    *argv);
@@ -1661,7 +1667,13 @@ main(int argc, char **argv)
 
 	if (runclient)
 		client(1, debug);
+
+	if (pat == NULL)
+		pat = ".*";
 
+	if (regcomp(&reg, pat, REG_BASIC | REG_ICASE | REG_NOSUB) != 0)
+		fatalx("invalid regexp: %s", pat);
+
 	for (i = 0; i < argc; ++i)
 		loadfile(argv[i]);
 
@@ -1676,6 +1688,9 @@ main(int argc, char **argv)
 
 	i = 0;
 	TAILQ_FOREACH(t, &tests, entry) {
+		if (regexec(&reg, t->name, 0, NULL, 0) != 0)
+			continue;
+
 		printf("===> [%d/%d] running test \"%s\"... ", i+1, ntests,
 		    t->name);
 		fflush(stdout);
@@ -1711,6 +1726,7 @@ main(int argc, char **argv)
 
 	popenv();
 	free(lastmsg);
+	regfree(&reg);
 
 	return failed != 0;
 }