Message ID | e1b89ae93e930cd902d1527955d588c3d0c15490.1706921262.git.steadmon@google.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | test-tool: add unit test suite runner | expand |
Josh Steadmon <steadmon@google.com> writes: > `test-tool run-command testsuite` currently assumes that it will only be > running the shell test suite, and therefore filters out anything that > does not match a hardcoded pattern of "t[0-9][0-9][0-9][0-9]-*.sh". > > Later in this series, we'll adapt `test-tool run-command testsuite` to > also support unit tests, which do not follow the same naming conventions > as the shell tests, so this hardcoded pattern is inconvenient. Makes sense to explain what future steps this prepares the codebase for like this. > Since `testsuite` also allows specifying patterns on the command-line, > let's just remove this pattern. As noted in [1], there are no longer any > uses of `testsuite` in our codebase, it should be OK to break backwards > compatibility in this case. We also add a new filter to avoid trying to > execute "." and "..", so that users who wish to execute every test in a > directory can do so without specifying a pattern. As we discussed in Peff's Makefile change that enumerates "which are the unit-test programs?" Generally, $(wildcard) and readdir() to slurp everything in a directory, including stuff that is an untracked cruft, is not an excellent idea. This is not an end-user facing program and we are in full control of its input (most notably, "which ones should we be running?"), I do not think it would be a huge issue, though. > [1] https://lore.kernel.org/git/850ea42c-f103-68d5-896b-9120e2628686@gmx.de/ > > Signed-off-by: Josh Steadmon <steadmon@google.com> > --- > t/helper/test-run-command.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/t/helper/test-run-command.c b/t/helper/test-run-command.c > index a41a54d9cb..e6bd792274 100644 > --- a/t/helper/test-run-command.c > +++ b/t/helper/test-run-command.c > @@ -175,9 +175,7 @@ static int testsuite(int argc, const char **argv) > while ((d = readdir(dir))) { > const char *p = d->d_name; > > - if (*p != 't' || !isdigit(p[1]) || !isdigit(p[2]) || > - !isdigit(p[3]) || !isdigit(p[4]) || p[5] != '-' || > - !ends_with(p, ".sh")) > + if (!strcmp(p, ".") || !strcmp(p, "..")) > continue; > > /* No pattern: match all */
On 2024.02.07 12:55, Junio C Hamano wrote: > Josh Steadmon <steadmon@google.com> writes: > > > `test-tool run-command testsuite` currently assumes that it will only be > > running the shell test suite, and therefore filters out anything that > > does not match a hardcoded pattern of "t[0-9][0-9][0-9][0-9]-*.sh". > > > > Later in this series, we'll adapt `test-tool run-command testsuite` to > > also support unit tests, which do not follow the same naming conventions > > as the shell tests, so this hardcoded pattern is inconvenient. > > Makes sense to explain what future steps this prepares the codebase > for like this. > > > Since `testsuite` also allows specifying patterns on the command-line, > > let's just remove this pattern. As noted in [1], there are no longer any > > uses of `testsuite` in our codebase, it should be OK to break backwards > > compatibility in this case. We also add a new filter to avoid trying to > > execute "." and "..", so that users who wish to execute every test in a > > directory can do so without specifying a pattern. > > As we discussed in Peff's Makefile change that enumerates "which are > the unit-test programs?" Generally, $(wildcard) and readdir() to > slurp everything in a directory, including stuff that is an > untracked cruft, is not an excellent idea. > > This is not an end-user facing program and we are in full control of > its input (most notably, "which ones should we be running?"), I do > not think it would be a huge issue, though. Would you prefer if I remove the default behavior of "run everything in the CWD" and require passing in at least one filename filter?
Josh Steadmon <steadmon@google.com> writes: >> As we discussed in Peff's Makefile change that enumerates "which are >> the unit-test programs?" Generally, $(wildcard) and readdir() to >> slurp everything in a directory, including stuff that is an >> untracked cruft, is not an excellent idea. >> >> This is not an end-user facing program and we are in full control of >> its input (most notably, "which ones should we be running?"), I do >> not think it would be a huge issue, though. > > Would you prefer if I remove the default behavior of "run everything in > the CWD" and require passing in at least one filename filter? No preference either way at all.
diff --git a/t/helper/test-run-command.c b/t/helper/test-run-command.c index a41a54d9cb..e6bd792274 100644 --- a/t/helper/test-run-command.c +++ b/t/helper/test-run-command.c @@ -175,9 +175,7 @@ static int testsuite(int argc, const char **argv) while ((d = readdir(dir))) { const char *p = d->d_name; - if (*p != 't' || !isdigit(p[1]) || !isdigit(p[2]) || - !isdigit(p[3]) || !isdigit(p[4]) || p[5] != '-' || - !ends_with(p, ".sh")) + if (!strcmp(p, ".") || !strcmp(p, "..")) continue; /* No pattern: match all */
`test-tool run-command testsuite` currently assumes that it will only be running the shell test suite, and therefore filters out anything that does not match a hardcoded pattern of "t[0-9][0-9][0-9][0-9]-*.sh". Later in this series, we'll adapt `test-tool run-command testsuite` to also support unit tests, which do not follow the same naming conventions as the shell tests, so this hardcoded pattern is inconvenient. Since `testsuite` also allows specifying patterns on the command-line, let's just remove this pattern. As noted in [1], there are no longer any uses of `testsuite` in our codebase, it should be OK to break backwards compatibility in this case. We also add a new filter to avoid trying to execute "." and "..", so that users who wish to execute every test in a directory can do so without specifying a pattern. [1] https://lore.kernel.org/git/850ea42c-f103-68d5-896b-9120e2628686@gmx.de/ Signed-off-by: Josh Steadmon <steadmon@google.com> --- t/helper/test-run-command.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)