Skip to content

Commit a2b55e2

Browse files
steadmongitster
authored andcommitted
test-tool run-command testsuite: support unit tests
Teach the testsuite runner in `test-tool run-command testsuite` how to run unit tests: if TEST_SHELL_PATH is not set, run the programs directly from CWD, rather than defaulting to "sh" as an interpreter. With this change, you can now use test-tool to run the unit tests: $ make $ cd t/unit-tests/bin $ ../../helper/test-tool run-command testsuite This should be helpful on Windows to allow running tests without requiring Perl (for `prove`), as discussed in [1] and [2]. This again breaks backwards compatibility, as it is now required to set TEST_SHELL_PATH properly for executing shell scripts, but again, as noted in [2], there are no longer any such invocations in our codebase. [1] https://lore.kernel.org/git/[email protected]/ [2] https://lore.kernel.org/git/[email protected]/ Signed-off-by: Josh Steadmon <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d28c5a5 commit a2b55e2

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

t/helper/test-run-command.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,22 @@ static int testsuite(int argc, const char **argv)
158158
.task_finished = test_finished,
159159
.data = &suite,
160160
};
161+
struct strbuf progpath = STRBUF_INIT;
162+
size_t path_prefix_len;
161163

162164
argc = parse_options(argc, argv, NULL, options,
163165
testsuite_usage, PARSE_OPT_STOP_AT_NON_OPTION);
164166

165167
if (max_jobs <= 0)
166168
max_jobs = online_cpus();
167169

170+
/*
171+
* If we run without a shell, execute the programs directly from CWD.
172+
*/
168173
suite.shell_path = getenv("TEST_SHELL_PATH");
169174
if (!suite.shell_path)
170-
suite.shell_path = "sh";
175+
strbuf_addstr(&progpath, "./");
176+
path_prefix_len = progpath.len;
171177

172178
dir = opendir(".");
173179
if (!dir)
@@ -180,13 +186,17 @@ static int testsuite(int argc, const char **argv)
180186

181187
/* No pattern: match all */
182188
if (!argc) {
183-
string_list_append(&suite.tests, p);
189+
strbuf_setlen(&progpath, path_prefix_len);
190+
strbuf_addstr(&progpath, p);
191+
string_list_append(&suite.tests, progpath.buf);
184192
continue;
185193
}
186194

187195
for (i = 0; i < argc; i++)
188196
if (!wildmatch(argv[i], p, 0)) {
189-
string_list_append(&suite.tests, p);
197+
strbuf_setlen(&progpath, path_prefix_len);
198+
strbuf_addstr(&progpath, p);
199+
string_list_append(&suite.tests, progpath.buf);
190200
break;
191201
}
192202
}
@@ -213,6 +223,7 @@ static int testsuite(int argc, const char **argv)
213223

214224
string_list_clear(&suite.tests, 0);
215225
string_list_clear(&suite.failed, 0);
226+
strbuf_release(&progpath);
216227

217228
return ret;
218229
}

0 commit comments

Comments
 (0)