diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2020-08-13 21:35:31 +0530 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2020-10-13 19:01:15 +0300 |
commit | 55cf399ff8b9c15300f26dd1a46045dda7d49f98 (patch) | |
tree | f0091f06afbd07c800306ea2a1237897e3e6f897 /mesonbuild/mtest.py | |
parent | dccff1f2bcf6e7b8e42fa7bea63b8532ad29b43a (diff) | |
download | meson-55cf399ff8b9c15300f26dd1a46045dda7d49f98.zip meson-55cf399ff8b9c15300f26dd1a46045dda7d49f98.tar.gz meson-55cf399ff8b9c15300f26dd1a46045dda7d49f98.tar.bz2 |
mtest: Allow filtering tests by subproject
You could always specify a list of tests to run by passing the names as
arguments to `meson test`. If there were multiple tests with that name (in the
same project or different subprojects), all of them would be run. Now you can:
1. Run all tests with the specified name from a specific subproject: `meson test subprojname:testname`
1. Run all tests defined in a specific subproject: `meson test subprojectname:`
Also forbid ':' in test names. We already forbid this elsewhere, so
should not be a big deal.
Diffstat (limited to 'mesonbuild/mtest.py')
-rw-r--r-- | mesonbuild/mtest.py | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py index caf4039..a5c2dda 100644 --- a/mesonbuild/mtest.py +++ b/mesonbuild/mtest.py @@ -124,7 +124,9 @@ def add_arguments(parser: argparse.ArgumentParser) -> None: parser.add_argument('--test-args', default=[], type=split_args, help='Arguments to pass to the specified test(s) or all tests') parser.add_argument('args', nargs='*', - help='Optional list of tests to run') + help='Optional list of test names to run. "testname" to run all tests with that name, ' + '"subprojname:testname" to specifically run "testname" from "subprojname", ' + '"subprojname:" to run all tests defined by "subprojname".') def returncode_to_status(retcode: int) -> str: @@ -1039,6 +1041,28 @@ class TestHarness: TestHarness.test_in_suites(test, self.options.include_suites)) and not TestHarness.test_in_suites(test, self.options.exclude_suites)) + def tests_from_args(self, tests: T.List[TestSerialisation]) -> T.Generator[TestSerialisation, None, None]: + ''' + Allow specifying test names like "meson test foo1 foo2", where test('foo1', ...) + + Also support specifying the subproject to run tests from like + "meson test subproj:" (all tests inside subproj) or "meson test subproj:foo1" + to run foo1 inside subproj. Coincidentally also "meson test :foo1" to + run all tests with that name across all subprojects, which is + identical to "meson test foo1" + ''' + for arg in self.options.args: + if ':' in arg: + subproj, name = arg.split(':', maxsplit=1) + else: + subproj, name = '', arg + for t in tests: + if subproj and t.project_name != subproj: + continue + if name and t.name != name: + continue + yield t + def get_tests(self) -> T.List[TestSerialisation]: if not self.tests: print('No tests defined.') @@ -1052,9 +1076,8 @@ class TestHarness: else: tests = self.tests - # allow specifying test names like "meson test foo1 foo2", where test('foo1', ...) if self.options.args: - tests = [t for t in tests if t.name in self.options.args] + tests = list(self.tests_from_args(tests)) if not tests: print('No suitable tests defined.') |