From 1fd70a2a004900b7d97d9fc560e87d33266ecfed Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Thu, 17 Aug 2023 20:44:42 -0400 Subject: [PATCH] tests: consolidate MESON_SKIP_TEST reporting and use it in unittests Previously, we only reported the skip reason when running project tests. --- run_project_tests.py | 26 +++++++------------------- run_single_test.py | 13 +++---------- run_tests.py | 9 +++++++++ unittests/baseplatformtests.py | 14 +++++++------- 4 files changed, 26 insertions(+), 36 deletions(-) diff --git a/run_project_tests.py b/run_project_tests.py index 27020caef..acfa284d7 100755 --- a/run_project_tests.py +++ b/run_project_tests.py @@ -53,10 +53,12 @@ from mesonbuild.mesonlib import MachineChoice, Popen_safe, TemporaryDirectoryWin from mesonbuild.mlog import blue, bold, cyan, green, red, yellow, normal_green from mesonbuild.coredata import backendlist, version as meson_version from mesonbuild.modules.python import PythonExternalProgram -from run_tests import get_fake_options, run_configure, get_meson_script -from run_tests import get_backend_commands, get_backend_args_for_dir, Backend -from run_tests import ensure_backend_detects_changes -from run_tests import guess_backend +from run_tests import ( + get_fake_options, run_configure, get_meson_script, get_backend_commands, + get_backend_args_for_dir, Backend, ensure_backend_detects_changes, + guess_backend, handle_meson_skip_test, +) + if T.TYPE_CHECKING: from types import FrameType @@ -1206,12 +1208,6 @@ class LogRunFuture: RunFutureUnion = T.Union[TestRunFuture, LogRunFuture] -def test_emits_skip_msg(line: str) -> bool: - for prefix in {'Problem encountered', 'Assert failed', 'Failed to configure the CMake subproject'}: - if f'{prefix}: MESON_SKIP_TEST' in line: - return True - return False - def _run_tests(all_tests: T.List[T.Tuple[str, T.List[TestDef], bool]], log_name_base: str, failfast: bool, @@ -1324,15 +1320,7 @@ def _run_tests(all_tests: T.List[T.Tuple[str, T.List[TestDef], bool]], skip_as_expected = True else: # skipped due to test outputting 'MESON_SKIP_TEST' - for l in result.stdo.splitlines(): - if test_emits_skip_msg(l): - is_skipped = True - offset = l.index('MESON_SKIP_TEST') + 16 - skip_reason = l[offset:].strip() - break - else: - is_skipped = False - skip_reason = '' + is_skipped, skip_reason = handle_meson_skip_test(result.stdo) if not skip_dont_care(t): skip_as_expected = (is_skipped == t.skip_expected) else: diff --git a/run_single_test.py b/run_single_test.py index eb9379acc..5cd4f5e9f 100755 --- a/run_single_test.py +++ b/run_single_test.py @@ -13,7 +13,8 @@ import pathlib import typing as T from mesonbuild import mlog -from run_project_tests import TestDef, load_test_json, run_test, BuildStep, test_emits_skip_msg +from run_tests import handle_meson_skip_test +from run_project_tests import TestDef, load_test_json, run_test, BuildStep from run_project_tests import setup_commands, detect_system_compiler, print_tool_versions if T.TYPE_CHECKING: @@ -69,15 +70,7 @@ def main() -> None: is_skipped = True skip_reason = 'not run because preconditions were not met' else: - for l in result.stdo.splitlines(): - if test_emits_skip_msg(l): - is_skipped = True - offset = l.index('MESON_SKIP_TEST') + 16 - skip_reason = l[offset:].strip() - break - else: - is_skipped = False - skip_reason = '' + is_skipped, skip_reason = handle_meson_skip_test(result.stdo) if is_skipped: msg = mlog.yellow('SKIP:') diff --git a/run_tests.py b/run_tests.py index cf0633783..699e29356 100755 --- a/run_tests.py +++ b/run_tests.py @@ -187,6 +187,15 @@ if mesonlib.is_windows() or mesonlib.is_cygwin(): else: exe_suffix = '' +def handle_meson_skip_test(out: str) -> T.Tuple[bool, str]: + for line in out.splitlines(): + for prefix in {'Problem encountered', 'Assert failed', 'Failed to configure the CMake subproject'}: + if f'{prefix}: MESON_SKIP_TEST' in line: + offset = line.index('MESON_SKIP_TEST') + 16 + reason = line[offset:].strip() + return (True, reason) + return (False, '') + def get_meson_script() -> str: ''' Guess the meson that corresponds to the `mesonbuild` that has been imported diff --git a/unittests/baseplatformtests.py b/unittests/baseplatformtests.py index 3008eb731..03ab1c521 100644 --- a/unittests/baseplatformtests.py +++ b/unittests/baseplatformtests.py @@ -41,7 +41,7 @@ import mesonbuild.modules.pkgconfig from run_tests import ( Backend, ensure_backend_detects_changes, get_backend_commands, get_builddir_target_args, get_meson_script, run_configure_inprocess, - run_mtest_inprocess + run_mtest_inprocess, handle_meson_skip_test, ) @@ -183,8 +183,9 @@ class BasePlatformTests(TestCase): print('stderr:') print(proc.stderr) if proc.returncode != 0: - if 'MESON_SKIP_TEST' in proc.stdout: - raise SkipTest('Project requested skipping.') + skipped, reason = handle_meson_skip_test(proc.stdout) + if skipped: + raise SkipTest(f'Project requested skipping: {reason}') raise subprocess.CalledProcessError(proc.returncode, command, output=proc.stdout) return proc.stdout @@ -234,8 +235,9 @@ class BasePlatformTests(TestCase): mesonbuild.mlog._logger.log_dir = None mesonbuild.mlog._logger.log_file = None - if 'MESON_SKIP_TEST' in out: - raise SkipTest('Project requested skipping.') + skipped, reason = handle_meson_skip_test(out) + if skipped: + raise SkipTest(f'Project requested skipping: {reason}') if returncode != 0: self._print_meson_log() print('Stdout:\n') @@ -247,8 +249,6 @@ class BasePlatformTests(TestCase): else: try: out = self._run(self.setup_command + args + extra_args + build_and_src_dir_args, override_envvars=override_envvars, workdir=workdir) - except SkipTest: - raise SkipTest('Project requested skipping: ' + srcdir) except Exception: if not allow_fail: self._print_meson_log()