Skip to content

Commit

Permalink
Deprecate should_error, renamed to expected_error and add success_ret…
Browse files Browse the repository at this point in the history
…urncode for exitcode tests
  • Loading branch information
gerioldman committed Sep 4, 2024
1 parent d299add commit 3c58a75
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
5 changes: 3 additions & 2 deletions mesonbuild/backend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ class TestSerialisation:
is_parallel: bool
cmd_args: T.List[str]
env: mesonlib.EnvironmentVariables
should_fail: bool
expected_fail: bool
success_returncode: int
timeout: T.Optional[int]
workdir: T.Optional[str]
extra_paths: T.List[str]
Expand Down Expand Up @@ -1284,7 +1285,7 @@ def create_test_serialisation(self, tests: T.List['Test']) -> T.List[TestSeriali
ts = TestSerialisation(t.get_name(), t.project_name, t.suite, cmd, is_cross,
exe_wrapper, self.environment.need_exe_wrapper(),
t.is_parallel, cmd_args, t_env,
t.should_fail, t.timeout, t.workdir,
t.expected_fail, t.success_returncode, t.timeout, t.workdir,
extra_paths, t.protocol, t.priority,
isinstance(exe, (build.Target, build.CustomTargetIndex)),
isinstance(exe, build.Executable),
Expand Down
11 changes: 10 additions & 1 deletion mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2258,7 +2258,8 @@ def make_test(self, node: mparser.BaseNode,
kwargs.get('is_parallel', False),
kwargs['args'],
env,
kwargs['should_fail'],
kwargs['expected_fail'],
kwargs['success_returncode'],
kwargs['timeout'],
kwargs['workdir'],
kwargs['protocol'],
Expand All @@ -2273,6 +2274,14 @@ def add_test(self, node: mparser.BaseNode,
if any(isinstance(i, ExternalProgram) for i in kwargs['args']):
FeatureNew.single_use('test with external_program in args', '1.6.0', self.subproject)

if kwargs['should_fail'] is not None and kwargs['expected_fail'] is not None:
raise InvalidArguments('Tried to use both \'should_fail\' and \'expected_fail\'')
elif kwargs['should_fail'] is not None:
mlog.deprecation('Use expected_fail instead of should_fail.',location=node)
kwargs['expected_fail'] = kwargs['should_fail']
elif kwargs['expected_fail'] is None:
kwargs['expected_fail'] = False

t = self.make_test(node, args, kwargs)
if is_base_test:
self.build.tests.append(t)
Expand Down
5 changes: 3 additions & 2 deletions mesonbuild/interpreter/interpreterobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ def __init__(self, name: str, project: str, suite: T.List[str],
is_parallel: bool,
cmd_args: T.List[T.Union[str, mesonlib.File, build.Target, ExternalProgram]],
env: mesonlib.EnvironmentVariables,
should_fail: bool, timeout: int, workdir: T.Optional[str], protocol: str,
expected_fail: bool, success_returncode: int, timeout: int, workdir: T.Optional[str], protocol: str,
priority: int, verbose: bool):
super().__init__()
self.name = name
Expand All @@ -766,7 +766,8 @@ def __init__(self, name: str, project: str, suite: T.List[str],
self.is_parallel = is_parallel
self.cmd_args = cmd_args
self.env = env
self.should_fail = should_fail
self.expected_fail = expected_fail
self.success_returncode = success_returncode
self.timeout = timeout
self.workdir = workdir
self.protocol = TestProtocol.from_str(protocol)
Expand Down
4 changes: 3 additions & 1 deletion mesonbuild/interpreter/kwargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class BaseTest(TypedDict):
"""Shared base for the Rust module."""

args: T.List[T.Union[str, File, build.Target, ExternalProgram]]
should_fail: bool
should_fail: T.Optional[bool]
expected_fail: T.Optional[bool]
success_returncode: int
timeout: int
workdir: T.Optional[str]
depends: T.List[T.Union[build.CustomTarget, build.BuildTarget]]
Expand Down
4 changes: 3 additions & 1 deletion mesonbuild/interpreter/type_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,9 @@ def link_whole_validator(values: T.List[T.Union[StaticLibrary, CustomTarget, Cus
TEST_KWS: T.List[KwargInfo] = [
KwargInfo('args', ContainerTypeInfo(list, (str, File, BuildTarget, CustomTarget, CustomTargetIndex, ExternalProgram)),
listify=True, default=[]),
KwargInfo('should_fail', bool, default=False),
KwargInfo('should_fail', T.Optional[bool], deprecated='1.6.0', deprecated_message='Use expected_fail instead of should_fail'),
KwargInfo('expected_fail', T.Optional[bool], since='1.6.0'),
KwargInfo('success_returncode', int, default=0, since='1.6.0'),
KwargInfo('timeout', int, default=30),
KwargInfo('workdir', (str, NoneType), default=None,
validator=lambda x: 'must be an absolute path' if not os.path.isabs(x) else None),
Expand Down
7 changes: 5 additions & 2 deletions mesonbuild/mtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,8 @@ def __init__(self, test: TestSerialisation, test_env: T.Dict[str, str],
self.additional_error = ''
self.cmd: T.Optional[T.List[str]] = None
self.env = test_env
self.should_fail = test.should_fail
self.expected_fail = test.expected_fail
self.success_returncode = test.success_returncode
self.project = test.project_name
self.junit: T.Optional[et.ElementTree] = None
self.is_parallel = is_parallel
Expand Down Expand Up @@ -982,7 +983,7 @@ def _complete(self) -> None:
if self.res == TestResult.RUNNING:
self.res = TestResult.OK
assert isinstance(self.res, TestResult)
if self.should_fail and self.res in (TestResult.OK, TestResult.FAIL):
if self.expected_fail and self.res in (TestResult.OK, TestResult.FAIL):
self.res = TestResult.UNEXPECTEDPASS if self.res is TestResult.OK else TestResult.EXPECTEDFAIL
if self.stdo and not self.stdo.endswith('\n'):
self.stdo += '\n'
Expand Down Expand Up @@ -1038,6 +1039,8 @@ class TestRunExitCode(TestRun):
def complete(self) -> None:
if self.res != TestResult.RUNNING:
pass
elif self.returncode == self.success_returncode:
self.res = TestResult.OK
elif self.returncode == GNU_SKIP_RETURNCODE:
self.res = TestResult.SKIP
elif self.returncode == GNU_ERROR_RETURNCODE:
Expand Down

0 comments on commit 3c58a75

Please sign in to comment.