Skip to content

Commit 59a46da

Browse files
committed
mtest: Fix test selection implementation
Omitting test()'s `suite` kwarg used to default to `test.suite==['']` because of how stringlistify() works. That had inconsistent behavior with `suite: []` which makes `test.suite==[]`. That changed when porting to typed_kwarg (mesonbuild#8855), which made the default `test.suite==[]`. Change `suite: []`, and missing kwarg, back to `test.suite==['']` which was the original intention. It has impact on `meson test --suite` selection, an empty `test.suite` list means that test is never going to be selected when `--suite` is used, even when we want all tests from a given subproject. It was also unclear what `--suite foo` means. Is `foo` a suite or a project name? It can now be either, it selects all tests from project `foo` as well as all tests from any project in suite `foo`.
1 parent ee17073 commit 59a46da

3 files changed

Lines changed: 28 additions & 29 deletions

File tree

mesonbuild/interpreter/type_checking.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,12 @@ def link_whole_validator(values: T.List[T.Union[StaticLibrary, CustomTarget, Cus
490490

491491
PRESERVE_PATH_KW: KwargInfo[bool] = KwargInfo('preserve_path', bool, default=False, since='0.63.0')
492492

493+
def suite_convertor(suite: T.List[str]) -> T.List[str]:
494+
# Ensure we always have at least one suite.
495+
if not suite:
496+
return ['']
497+
return suite
498+
493499
TEST_KWS_NO_ARGS: T.List[KwargInfo] = [
494500
KwargInfo('should_fail', bool, default=False),
495501
KwargInfo('timeout', int, default=30),
@@ -503,7 +509,7 @@ def link_whole_validator(values: T.List[T.Union[StaticLibrary, CustomTarget, Cus
503509
# TODO: env needs reworks of the way the environment variable holder itself works probably
504510
ENV_KW,
505511
DEPENDS_KW.evolve(since='0.46.0'),
506-
KwargInfo('suite', ContainerTypeInfo(list, str), listify=True, default=['']), # yes, a list of empty string
512+
KwargInfo('suite', ContainerTypeInfo(list, str), listify=True, default=[], convertor=suite_convertor),
507513
KwargInfo('verbose', bool, default=False, since='0.62.0'),
508514
]
509515

mesonbuild/mtest.py

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,29 +1939,22 @@ def test_in_suites(test: TestSerialisation, suites: T.List[str]) -> bool:
19391939
for prjst in test.suite:
19401940
(prj, st) = TestHarness.split_suite_string(prjst)
19411941

1942-
# the SUITE can be passed as
1943-
# suite_name
1944-
# or
1945-
# project_name:suite_name
1946-
# so we need to select only the test belonging to project_name
1947-
1948-
# this if handle the first case (i.e., SUITE == suite_name)
1949-
1950-
# in this way we can run tests belonging to different
1951-
# (sub)projects which share the same suite_name
1952-
if not st_match and st == prj_match:
1953-
return True
1954-
1955-
# these two conditions are needed to handle the second option
1956-
# i.e., SUITE == project_name:suite_name
1957-
1958-
# in this way we select the only the tests of
1959-
# project_name with suite_name
1960-
if prj_match and prj != prj_match:
1961-
continue
1962-
if st_match and st != st_match:
1963-
continue
1964-
return True
1942+
# The SUITE can be passed as
1943+
# - `name` - We select tests belonging to (sub)project OR suite
1944+
# with the given name.
1945+
# - `:suite_name` - We select tests belonging to any (sub)projects
1946+
# and in suite_name.
1947+
# - `project_name:suite_name` - We select tests belonging
1948+
# to project_name and in suite_name.
1949+
if not st_match:
1950+
if prj_match in {prj, st}:
1951+
return True
1952+
elif not prj_match:
1953+
if st == st_match:
1954+
return True
1955+
else:
1956+
if prj == prj_match and st == st_match:
1957+
return True
19651958
return False
19661959

19671960
def test_suitable(self, test: TestSerialisation) -> bool:

unittests/allplatformstests.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -911,11 +911,11 @@ def test_suite_selection(self):
911911

912912
self.assertFailedTestCount(1, self.mtest_command + ['--suite', 'mainprj'])
913913
self.assertFailedTestCount(0, self.mtest_command + ['--suite', 'subprjsucc'])
914-
self.assertFailedTestCount(1, self.mtest_command + ['--suite', 'subprjfail'])
914+
self.assertFailedTestCount(2, self.mtest_command + ['--suite', 'subprjfail'])
915915
self.assertFailedTestCount(1, self.mtest_command + ['--suite', 'subprjmix'])
916916
self.assertFailedTestCount(3, self.mtest_command + ['--no-suite', 'mainprj'])
917917
self.assertFailedTestCount(4, self.mtest_command + ['--no-suite', 'subprjsucc'])
918-
self.assertFailedTestCount(3, self.mtest_command + ['--no-suite', 'subprjfail'])
918+
self.assertFailedTestCount(2, self.mtest_command + ['--no-suite', 'subprjfail'])
919919
self.assertFailedTestCount(3, self.mtest_command + ['--no-suite', 'subprjmix'])
920920

921921
self.assertFailedTestCount(1, self.mtest_command + ['--suite', 'mainprj:fail'])
@@ -938,9 +938,9 @@ def test_suite_selection(self):
938938
self.assertFailedTestCount(3, self.mtest_command + ['--no-suite', 'subprjmix:fail'])
939939
self.assertFailedTestCount(4, self.mtest_command + ['--no-suite', 'subprjmix:success'])
940940

941-
self.assertFailedTestCount(2, self.mtest_command + ['--suite', 'subprjfail', '--suite', 'subprjmix:fail'])
942-
self.assertFailedTestCount(3, self.mtest_command + ['--suite', 'subprjfail', '--suite', 'subprjmix', '--suite', 'mainprj'])
943-
self.assertFailedTestCount(2, self.mtest_command + ['--suite', 'subprjfail', '--suite', 'subprjmix', '--suite', 'mainprj', '--no-suite', 'subprjmix:fail'])
941+
self.assertFailedTestCount(3, self.mtest_command + ['--suite', 'subprjfail', '--suite', 'subprjmix:fail'])
942+
self.assertFailedTestCount(4, self.mtest_command + ['--suite', 'subprjfail', '--suite', 'subprjmix', '--suite', 'mainprj'])
943+
self.assertFailedTestCount(3, self.mtest_command + ['--suite', 'subprjfail', '--suite', 'subprjmix', '--suite', 'mainprj', '--no-suite', 'subprjmix:fail'])
944944
self.assertFailedTestCount(1, self.mtest_command + ['--suite', 'subprjfail', '--suite', 'subprjmix', '--suite', 'mainprj', '--no-suite', 'subprjmix:fail', 'mainprj-failing_test'])
945945

946946
self.assertFailedTestCount(2, self.mtest_command + ['--no-suite', 'subprjfail:fail', '--no-suite', 'subprjmix:fail'])

0 commit comments

Comments
 (0)