Skip to content

Commit

Permalink
add skip kw to test function
Browse files Browse the repository at this point in the history
  • Loading branch information
bruchar1 committed Nov 20, 2023
1 parent dea72e4 commit 0af0a6c
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 4 deletions.
6 changes: 6 additions & 0 deletions docs/markdown/snippets/skip_tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Added keyword to skip a test

[[test]] function now has a `skip` keyword to mark it as skipped.

The usecase is when the execution of the test is based on a condition,
but you want to keep the test in the list of available tests.
7 changes: 7 additions & 0 deletions docs/yaml/functions/benchmark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ kwargs:
'NAME2=value2']`, or an [[@env]] object which allows more sophisticated
environment juggling. *(Since 0.52.0)* A dictionary is also accepted.
skip:
type: bool
default: false
since: 1.4.0
description: |
when true, the test is not run, but marked as skip.
should_fail:
type: bool
default: false
Expand Down
3 changes: 2 additions & 1 deletion mesonbuild/backend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ class TestSerialisation:
cmd_args: T.List[str]
env: mesonlib.EnvironmentVariables
should_fail: bool
skip: bool
timeout: T.Optional[int]
workdir: T.Optional[str]
extra_paths: T.List[str]
Expand Down Expand Up @@ -1281,7 +1282,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.should_fail, t.skip, t.timeout, t.workdir,
extra_paths, t.protocol, t.priority,
isinstance(exe, build.Target),
isinstance(exe, build.Executable),
Expand Down
3 changes: 2 additions & 1 deletion mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2195,7 +2195,7 @@ def make_test(self, node: mparser.BaseNode,
name = name.replace(':', '_')
exe = args[1]
if isinstance(exe, ExternalProgram):
if not exe.found():
if not exe.found() and not kwargs['skip']:
raise InvalidArguments('Tried to use not-found external program as test exe')
elif isinstance(exe, mesonlib.File):
exe = self.find_program_impl([exe])
Expand All @@ -2222,6 +2222,7 @@ def make_test(self, node: mparser.BaseNode,
kwargs['args'],
env,
kwargs['should_fail'],
kwargs['skip'],
kwargs['timeout'],
kwargs['workdir'],
kwargs['protocol'],
Expand Down
3 changes: 2 additions & 1 deletion mesonbuild/interpreter/interpreterobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,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]],
env: mesonlib.EnvironmentVariables,
should_fail: bool, timeout: int, workdir: T.Optional[str], protocol: str,
should_fail: bool, skip: bool, timeout: int, workdir: T.Optional[str], protocol: str,
priority: int, verbose: bool):
super().__init__()
self.name = name
Expand All @@ -742,6 +742,7 @@ 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.skip = skip
self.should_fail = should_fail
self.timeout = timeout
self.workdir = workdir
Expand Down
1 change: 1 addition & 0 deletions mesonbuild/interpreter/kwargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class BaseTest(TypedDict):
depends: T.List[T.Union[build.CustomTarget, build.BuildTarget]]
priority: int
env: EnvironmentVariables
skip: bool
suite: T.List[str]


Expand Down
1 change: 1 addition & 0 deletions mesonbuild/interpreter/type_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ def link_whole_validator(values: T.List[T.Union[StaticLibrary, CustomTarget, Cus
# TODO: env needs reworks of the way the environment variable holder itself works probably
ENV_KW,
DEPENDS_KW.evolve(since='0.46.0'),
KwargInfo('skip', bool, default=False, since='1.4.0'),
KwargInfo('suite', ContainerTypeInfo(list, str), listify=True, default=['']), # yes, a list of empty string
KwargInfo('verbose', bool, default=False, since='0.62.0'),
]
Expand Down
8 changes: 7 additions & 1 deletion mesonbuild/mtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,8 @@ def _get_test_cmd(self) -> T.Optional[T.List[str]]:
testentry = self.test.fname[0]
if self.options.no_rebuild and self.test.cmd_is_built and not os.path.isfile(testentry):
raise TestException(f'The test program {testentry!r} does not exist. Cannot run tests before building them.')
if self.test.skip and not testentry:
return None # In case we skip a not found test command
if testentry.endswith('.jar'):
return ['java', '-jar'] + self.test.fname
elif not self.test.is_cross_built and run_with_mono(testentry):
Expand Down Expand Up @@ -1488,7 +1490,11 @@ def timeout(self) -> T.Optional[int]:
return self.runobj.timeout

async def run(self, harness: 'TestHarness') -> TestRun:
if self.cmd is None:
if self.test.skip:
self.stdo = 'Test marked as skip.'
harness.log_start_test(self.runobj)
self.runobj.complete_skip()
elif self.cmd is None:
self.stdo = 'Not run because cannot execute cross compiled binaries.'
harness.log_start_test(self.runobj)
self.runobj.complete_skip()
Expand Down
28 changes: 28 additions & 0 deletions test cases/common/273 skip test/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
project(
'skip test',
meson_version: '>=1.4.0',
)

py = find_program('python3')
foo = find_program('not_a_program', required: false)

test(
'skip',
py,
args: ['-c', 'raise SystemExit(1)'],
skip: true,
)

test(
'dont skip',
py,
args: ['-c', 'raise SystemExit(1)'],
skip: false,
should_fail: true,
)

test(
'not found',
foo,
skip: not foo.found(),
)

0 comments on commit 0af0a6c

Please sign in to comment.