Skip to content

Commit

Permalink
interpreter, rust: move "args" out of BaseTest
Browse files Browse the repository at this point in the history
rust.doctest() will have to typecheck that to a list of strings,
no other argument types are allowed.  Extract the field out of
BaseTest, placing it in FuncBenchmark and the rust modules's
FuncTest.

Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
bonzini committed Dec 12, 2024
1 parent 45d7356 commit c914eaa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion mesonbuild/interpreter/kwargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class BaseTest(TypedDict):

"""Shared base for the Rust module."""

args: T.List[T.Union[str, File, build.Target, ExternalProgram]]
should_fail: bool
timeout: int
workdir: T.Optional[str]
Expand All @@ -48,10 +47,13 @@ class BaseTest(TypedDict):
suite: T.List[str]


TestArgs = T.Union[str, File, build.Target, ExternalProgram]

class FuncBenchmark(BaseTest):

"""Keyword Arguments shared between `test` and `benchmark`."""

args: T.List[TestArgs]
protocol: Literal['exitcode', 'tap', 'gtest', 'rust']


Expand Down
9 changes: 6 additions & 3 deletions mesonbuild/interpreter/type_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,7 @@ def link_whole_validator(values: T.List[T.Union[StaticLibrary, CustomTarget, Cus

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

TEST_KWS: T.List[KwargInfo] = [
KwargInfo('args', ContainerTypeInfo(list, (str, File, BuildTarget, CustomTarget, CustomTargetIndex, ExternalProgram)),
listify=True, default=[]),
TEST_KWS_NO_ARGS: T.List[KwargInfo] = [
KwargInfo('should_fail', bool, default=False),
KwargInfo('timeout', int, default=30),
KwargInfo('workdir', (str, NoneType), default=None,
Expand All @@ -503,6 +501,11 @@ def link_whole_validator(values: T.List[T.Union[StaticLibrary, CustomTarget, Cus
KwargInfo('verbose', bool, default=False, since='0.62.0'),
]

TEST_KWS: T.List[KwargInfo] = TEST_KWS_NO_ARGS + [
KwargInfo('args', ContainerTypeInfo(list, (str, File, BuildTarget, CustomTarget, CustomTargetIndex, ExternalProgram)),
listify=True, default=[]),
]

# Cannot have a default value because we need to check that rust_crate_type and
# rust_abi are mutually exclusive.
RUST_CRATE_TYPE_KW: KwargInfo[T.Union[str, None]] = KwargInfo(
Expand Down
3 changes: 2 additions & 1 deletion mesonbuild/modules/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@

from typing_extensions import TypedDict, Literal

class FuncTest(_kwargs.BaseTest):
class FuncTest(TypedDict, _kwargs.BaseTest):

args: T.List[_kwargs.TestArgs]
dependencies: T.List[T.Union[Dependency, ExternalLibrary]]
is_parallel: bool
link_with: T.List[LibTypes]
Expand Down

0 comments on commit c914eaa

Please sign in to comment.