Commit Diff


commit - 3b1814ed992e43565c9f7b4339aa9438676df79d
commit + a0ec53a25d9149f8c3421362edd034c38ff4684e
blob - 6da049b0758a48894158408f942e91823baa3ade
blob + 6397e607c9139b281baf63e439a935b9899bd2fd
--- ninepscript/ninepscript.5
+++ ninepscript/ninepscript.5
@@ -12,7 +12,7 @@
 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 .\"
-.Dd $Mdocdate: December 02 2021$
+.Dd $Mdocdate: January 09 2022$
 .Dt NINEPSCRIPT 5
 .Os
 .Sh NAME
@@ -143,16 +143,10 @@ are defined to the value passed by the caller.
 A routine may be called only within another routine body or inside a
 .Ic testing
 body.
-.It Ic testing Ar reason Ic dir Ar path Brq code ...
+.It Ic testing Ar reason Brq code ...
 Define a test case.
 .Ar reason
-is what the test block is about and
-.Ar path
-is the path to the root directory where the test will be executed.
-.Ar reason
-and
-.Ar path
-must be string literals.
+is what the test block is about and must be a string literal.
 .El
 .Pp
 Inside a
blob - 2df71001f2c0ddff2c4217feba1820fecb17df36
blob + 01d853ccaae448385ae9ff6dc79eb5a64cd8fb09
--- ninepscript/ninepscript.8
+++ ninepscript/ninepscript.8
@@ -12,7 +12,7 @@
 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 .\"
-.Dd $Mdocdate: December 02 2021$
+.Dd $Mdocdate: January 09 2022$
 .Dt NINEPSCRIPT 8
 .Os
 .Sh NAME
@@ -21,6 +21,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl nv
+.Fl r Ar dir
 .Op Fl x Ar pattern
 .Ar
 .Sh DESCRIPTION
@@ -37,6 +38,10 @@ The options are as follows:
 .It Fl n
 don't run the test, check only the syntax of the provided
 .Ar files .
+.It Fl r Ar dir
+Use the specified
+.Ar
+as root for the tests.
 .It Fl v
 verbose logging, print more information during the tests execution.
 .It Fl x Ar pattern
blob - d8897db51f613efeec14222cf68a621ef949d128
blob + 4eaa64c699eaf0005fe49c0997355c654b84c84d
--- ninepscript/parse.y
+++ ninepscript/parse.y
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
+ * Copyright (c) 2021, 2022 Omar Polo <op@omarpolo.com>
  * Copyright (c) 2018 Florian Obser <florian@openbsd.org>
  * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org>
  * Copyright (c) 2004 Ryan McBride <mcbride@openbsd.org>
@@ -90,7 +90,6 @@ typedef struct {
 
 %token	ASSERT
 %token	CONST
-%token	DIR
 %token	ERROR
 %token	INCLUDE
 %token	PROC
@@ -265,10 +264,10 @@ massert	: asserti nl | massert asserti nl ;
 asserti	: check			{ block_push(op_assert($1)); }
 	;
 
-test	: TESTING STRING DIR STRING {
+test	: TESTING STRING {
 		prepare_test();
 	} testopt '{' optnl block '}' {
-		test_done(shouldfail, $2, $4);
+		test_done(shouldfail, $2);
 		shouldfail = 0;
 	}
 	;
@@ -313,7 +312,6 @@ lookup(char *s)
 	static const struct keywords keywords[] = {
 		{"assert",	ASSERT},
 		{"const",	CONST},
-		{"dir",		DIR},
 		{"include",	INCLUDE},
 		{"proc",	PROC},
 		{"repeat",	REPEAT},
@@ -453,7 +451,6 @@ yylex(void)
 	switch (x = my_yylex()) {
 	case ASSERT: puts("assert"); break;
 	case CONST: puts("const"); break;
-	case DIR: puts("dir"); break;
 	case ERROR: puts("error"); break;
 	case INCLUDE: puts("include"); break;
 	case PROC: puts("proc"); break;
blob - 788436caccb3595142dff06a88ed10cba5912893
blob + 74b0934f6ed8a3dc82f3aaef45fb00f3b3fcac40
--- ninepscript/script.c
+++ ninepscript/script.c
@@ -50,6 +50,8 @@
 #endif
 
 static const char	*argv0;
+static const char	*dir;
+static uid_t		 uid;
 
 static uint8_t		*lastmsg;
 
@@ -1280,14 +1282,13 @@ prepare_test(void)
 }
 
 void
-test_done(int shouldfail, char *name, char *dir)
+test_done(int shouldfail, char *name)
 {
 	struct test	*test;
 
 	test = xcalloc(1, sizeof(*test));
 	test->shouldfail = shouldfail;
 	test->name = name;
-	test->dir = dir;
 	test->body = finalize(&blocks, NULL);
 
 	if (TAILQ_EMPTY(&tests))
@@ -1591,18 +1592,14 @@ static void
 prepare_child_for_test(struct test *t)
 {
 	struct passwd	*pw;
-	struct stat	 sb;
 
-	if (stat(t->dir, &sb) == -1)
-		fatal("stat(\"%s\")", t->dir);
+	if ((pw = getpwuid(uid)) == NULL)
+		fatal("getpwuid(%d)", uid);
 
-	if ((pw = getpwuid(sb.st_uid)) == NULL)
-		fatal("getpwuid(%d)", sb.st_uid);
-
 	imsg_compose(&ibuf, IMSG_AUTH, 0, 0, -1,
 	    pw->pw_name, strlen(pw->pw_name)+1);
 	imsg_compose(&ibuf, IMSG_AUTH_DIR, 0, 0, -1,
-	    t->dir, strlen(t->dir)+1);
+	    dir, strlen(dir)+1);
 
 	if (imsg_flush(&ibuf) == -1)
 		fatal("imsg_flush");
@@ -1657,6 +1654,7 @@ run_test(struct test *t)
 int
 main(int argc, char **argv)
 {
+	struct stat	 sb;
 	struct test	*t;
 	int		 ch, i, r, passed = 0, failed = 0, skipped = 0;
 	int		 runclient = 0;
@@ -1680,7 +1678,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:vx:")) != -1) {
+	while ((ch = getopt(argc, argv, "nT:r:vx:")) != -1) {
 		switch (ch) {
 		case 'n':
 			syntaxcheck = 1;
@@ -1689,6 +1687,9 @@ main(int argc, char **argv)
 			assert(*optarg == 'c');
                         runclient = 1;
 			break;
+		case 'r':
+			dir = optarg;
+			break;
 		case 'v':
 			debug = 1;
 			break;
@@ -1707,6 +1708,13 @@ main(int argc, char **argv)
 	if (runclient)
 		client(1, debug);
 
+	if (dir == NULL)
+		fatal("missing root test dir");
+	
+	if (stat(dir, &sb) == -1)
+		fatal("stat(\"%s\")", dir);
+	uid = sb.st_uid;
+
 	if (pat == NULL)
 		pat = ".*";
 
blob - 1e5584e6ac031d9590e267d34b6c282095a7a1be
blob + 7c619931b543c1d0e22c0879155428e9b2586f5f
--- ninepscript/script.h
+++ ninepscript/script.h
@@ -150,7 +150,6 @@ struct test {
 	TAILQ_ENTRY(test)	 entry;
 	int			 shouldfail;
 	char			*name;
-	char			*dir;
 	struct op		*body;
 };
 
@@ -209,7 +208,7 @@ struct proc	*proc_by_name(const char *);
 
 /* testing */
 void		 prepare_test(void);
-void		 test_done(int, char *, char *);
+void		 test_done(int, char *);
 
 /* np.y */
 void		 loadfile(const char *);
blob - dd15078e8b5ab344f1694f8e354a235160b15ee7
blob + 52985aebed33c7b84c4b01d40d16ddedbc93d46e
--- regress/ninepscript/io-suite.9ps
+++ regress/ninepscript/io-suite.9ps
@@ -1,6 +1,6 @@
 include "lib.9ps"
 
-testing "open + clunk works" dir "./../root" {
+testing "open + clunk works" {
 	mount(0, "/")
 	walk(0, 1, "dir", "subdir", "file")
 	expect(Rwalk)
@@ -14,7 +14,7 @@ testing "open + clunk works" dir "./../root" {
 	assert m.type == Rclunk
 }
 
-testing "can open directories" dir "./../root" {
+testing "can open directories" {
 	mount(0, "/")
 	walk(0, 1, "dir", "subdir")
 	expect(Rwalk)
@@ -28,7 +28,7 @@ testing "can open directories" dir "./../root" {
 	assert m.type == Rclunk
 }
 
-testing "can't open directories for writing" dir "./../root" {
+testing "can't open directories for writing" {
 	mount(0, "/")
 	walk(0, 1, "dir")
 	expect(Rwalk)
blob - ab1b801eb99c1408f60afdd75fc9e706cf425010
blob + 734d37e92b27e505d0e8f0f06719f8d12c763eca
--- regress/ninepscript/misc-suite.9ps
+++ regress/ninepscript/misc-suite.9ps
@@ -1,17 +1,17 @@
 include "lib.9ps"
 
-testing "if version works" dir "./../root" {
+testing "if version works" {
 	send(Tversion, notag, msize, np2000)
 	m = recv()
 	assert m.type == Rversion
 }
 
-testing "fails when sending a R-message" dir "./../root" {
+testing "fails when sending a R-message" {
 	send(Rversion, notag, msize, np2000)
 	should-fail recv() : "the connection should have been closed"
 }
 
-testing "multiple attach" dir "./../root" {
+testing "multiple attach" {
 	version(msize, np2000)
 
 	m = recv()
@@ -41,7 +41,7 @@ testing "multiple attach" dir "./../root" {
 	)
 }
 
-testing "don't close used qids" dir "./../root" {
+testing "don't close used qids" {
 	mount(0, "/")
 
 	walk(0, 2, "dir")
blob - 8a0a8ca13b19b78d916dc6137b301ea2a0dfa2a2
blob + 430c60dedde933e32688ac1b69ea96cc2b604ba3
--- regress/ninepscript/walk-suite.9ps
+++ regress/ninepscript/walk-suite.9ps
@@ -2,7 +2,7 @@ include "lib.9ps"
 
 # TODO: add a test that tries to do a walk after opening a fid for i/o.
 
-testing "walk to a directory" dir "./../root" {
+testing "walk to a directory" {
 	mount(0, "/")
 	walk(0, 1, "dir", "subdir")
 
@@ -15,7 +15,7 @@ testing "walk to a directory" dir "./../root" {
 	)
 }
 
-testing "walk to a file" dir "./../root" {
+testing "walk to a file" {
 	mount(0, "/")
 	walk(0, 1, "dir", "subdir", "file")
 
@@ -29,7 +29,7 @@ testing "walk to a file" dir "./../root" {
 	)
 }
 
-testing "can't walk from a file" dir "./../root" {
+testing "can't walk from a file" {
 	mount(0, "/")
 
 	walk(0, 1, "dir", "a-file")
@@ -39,31 +39,31 @@ testing "can't walk from a file" dir "./../root" {
 	expect-error()
 }
 
-testing "walk with invalid fid" dir "./../root" {
+testing "walk with invalid fid" {
 	mount(0, "/")
 	walk(1, 2)
 	expect-error()
 }
 
-testing "walk with empty string" dir "./../root" {
+testing "walk with empty string" {
 	mount(0, "/")
 	walk(0, 1, "")
 	expect-error()
 }
 
-testing "walk to a non-existant file" dir "./../root" {
+testing "walk to a non-existant file" {
 	mount(0, "/")
 	walk(0, 1, "non-exists")
 	expect-error()
 }
 
-testing "walk with an invalid component" dir "./../root" {
+testing "walk with an invalid component" {
 	mount(0, "/")
 	walk(0, 1, "/non-exists")
 	expect-error()
 }
 
-testing "zero-path walk don't reply with a qid" dir "./../root" {
+testing "zero-path walk don't reply with a qid" {
 	mount(0, "/")
 	walk(0, 1)
 	m = recv()