diff --git a/run_project_tests.py b/run_project_tests.py index 0650f868c..8550bbfe4 100755 --- a/run_project_tests.py +++ b/run_project_tests.py @@ -92,11 +92,14 @@ class TestResult: @functools.total_ordering class TestDef: - def __init__(self, path: Path, name: T.Optional[str], args: T.List[str], skip: bool = False): + def __init__(self, path: Path, name: T.Optional[str], args: T.List[str], skip: bool = False, env_update: T.Optional[T.Dict[str, str]] = None): self.path = path self.name = name self.args = args self.skip = skip + self.env = os.environ.copy() + if env_update is not None: + self.env.update(env_update) def __repr__(self) -> str: return '<{}: {:<48} [{}: {}] -- {}>'.format(type(self).__name__, str(self.path), self.name, self.args, self.skip) @@ -416,7 +419,6 @@ def _run_test(test: TestDef, test_build_dir: str, install_dir: str, extra_args, compile_commands, clean_commands, install_commands, uninstall_commands = commands test_args = parse_test_args(testdir) gen_start = time.time() - setup_env = None # Configure in-process if pass_prefix_to_test(test.path): gen_args = ['--prefix', 'x:/usr'] if mesonlib.is_windows() else ['--prefix', '/usr'] @@ -431,15 +433,7 @@ def _run_test(test: TestDef, test_build_dir: str, install_dir: str, extra_args, gen_args.extend(['--native-file', nativefile.as_posix()]) if crossfile.exists(): gen_args.extend(['--cross-file', crossfile.as_posix()]) - setup_env_file = os.path.join(testdir, 'setup_env.json') - if os.path.exists(setup_env_file): - setup_env = os.environ.copy() - with open(setup_env_file, 'r') as fp: - data = json.load(fp) - for key, val in data.items(): - val = val.replace('@ROOT@', os.path.abspath(testdir)) - setup_env[key] = val - (returncode, stdo, stde) = run_configure(gen_args, env=setup_env) + (returncode, stdo, stde) = run_configure(gen_args, env=test.env) try: logfile = Path(test_build_dir, 'meson-logs', 'meson-log.txt') mesonlog = logfile.open(errors='ignore', encoding='utf-8').read() @@ -530,14 +524,31 @@ def gather_tests(testdir: Path) -> T.List[TestDef]: test_defs = [TestDef(testdir / t, None, []) for t in tests] all_tests = [] # type: T.List[TestDef] for t in test_defs: - matrix_file = t.path / 'test_matrix.json' - if not matrix_file.is_file(): + test_def_file = t.path / 'test.json' + if not test_def_file.is_file(): all_tests += [t] continue - # Build multiple tests from matrix definition + test_def = json.loads(test_def_file.read_text()) + + # Handle additional environment variables + env = None # type: T.Dict[str, str] + if 'env' in test_def: + assert isinstance(test_def['env'], dict) + env = test_def['env'] + for key, val in env.items(): + val = val.replace('@ROOT@', t.path.resolve().as_posix()) + env[key] = val + + # Skip the matrix code and just update the existing test + if 'matrix' not in test_def: + t.env.update(env) + all_tests += [t] + continue + + # 'matrix; entry is present, so build multiple tests from matrix definition opt_list = [] # type: T.List[T.List[T.Tuple[str, bool]]] - matrix = json.loads(matrix_file.read_text()) + matrix = test_def['matrix'] assert "options" in matrix for key, val in matrix["options"].items(): assert isinstance(val, list) @@ -598,7 +609,7 @@ def gather_tests(testdir: Path) -> T.List[TestDef]: name = ' '.join([x[0] for x in i if x[0] is not None]) opts = ['-D' + x[0] for x in i if x[0] is not None] skip = any([x[1] for x in i]) - all_tests += [TestDef(t.path, name, opts, skip)] + all_tests += [TestDef(t.path, name, opts, skip, env_update=env)] return sorted(all_tests) diff --git a/test cases/cmake/16 threads/test.json b/test cases/cmake/16 threads/test.json new file mode 100644 index 000000000..db788b113 --- /dev/null +++ b/test cases/cmake/16 threads/test.json @@ -0,0 +1,11 @@ +{ + "matrix": { + "options": { + "use_pthread": [ + { "val": "ON" }, + { "val": "OFF" }, + { "val": "NOT_SET" } + ] + } + } +} diff --git a/test cases/cmake/16 threads/test_matrix.json b/test cases/cmake/16 threads/test_matrix.json deleted file mode 100644 index 1c2c54569..000000000 --- a/test cases/cmake/16 threads/test_matrix.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "options": { - "use_pthread": [ - { "val": "ON" }, - { "val": "OFF" }, - { "val": "NOT_SET" } - ] - } -} diff --git a/test cases/frameworks/1 boost/test.json b/test cases/frameworks/1 boost/test.json new file mode 100644 index 000000000..f4412d2ef --- /dev/null +++ b/test cases/frameworks/1 boost/test.json @@ -0,0 +1,21 @@ +{ + "matrix": { + "options": { + "static": [ + { "val": "true", "skip_on_env": [ "SKIP_STATIC_BOOST" ] }, + { "val": "false" } + ], + "b_vscrt": [ + { "val": null }, + { "val": "md", "compilers": { "cpp": [ "msvc" ] } }, + { "val": "mdd", "compilers": { "cpp": [ "msvc" ] } }, + { "val": "mt", "compilers": { "cpp": [ "msvc" ] } }, + { "val": "mtd", "compilers": { "cpp": [ "msvc" ] } } + ] + }, + "exclude": [ + { "static": "false", "b_vscrt": "mt" }, + { "static": "false", "b_vscrt": "mtd" } + ] + } +} diff --git a/test cases/frameworks/1 boost/test_matrix.json b/test cases/frameworks/1 boost/test_matrix.json deleted file mode 100644 index 730610ee5..000000000 --- a/test cases/frameworks/1 boost/test_matrix.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "options": { - "static": [ - { "val": "true", "skip_on_env": [ "SKIP_STATIC_BOOST" ] }, - { "val": "false" } - ], - "b_vscrt": [ - { "val": null }, - { "val": "md", "compilers": { "cpp": [ "msvc" ] } }, - { "val": "mdd", "compilers": { "cpp": [ "msvc" ] } }, - { "val": "mt", "compilers": { "cpp": [ "msvc" ] } }, - { "val": "mtd", "compilers": { "cpp": [ "msvc" ] } } - ] - }, - "exclude": [ - { "static": "false", "b_vscrt": "mt" }, - { "static": "false", "b_vscrt": "mtd" } - ] -} diff --git a/test cases/linuxlike/13 cmake dependency/setup_env.json b/test cases/linuxlike/13 cmake dependency/setup_env.json deleted file mode 100644 index aa1537496..000000000 --- a/test cases/linuxlike/13 cmake dependency/setup_env.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "CMAKE_PREFIX_PATH": "@ROOT@/cmake_pref_env" -} diff --git a/test cases/linuxlike/13 cmake dependency/test.json b/test cases/linuxlike/13 cmake dependency/test.json new file mode 100644 index 000000000..565713ee6 --- /dev/null +++ b/test cases/linuxlike/13 cmake dependency/test.json @@ -0,0 +1,5 @@ +{ + "env": { + "CMAKE_PREFIX_PATH": "@ROOT@/cmake_pref_env" + } +}