run_project_tests: split json parsing code from test gathering code
@@ -620,12 +620,9 @@ def _run_test(test: TestDef, test_build_dir: str, install_dir: str, extra_args,
return testresult
-def gather_tests(testdir: Path, stdout_mandatory: bool) -> T.List[TestDef]:
- tests = [t.name for t in testdir.iterdir() if t.is_dir()]
- tests = [t for t in tests if not t.startswith('.')] # Filter non-tests files (dot files, etc)
- test_defs = [TestDef(testdir / t, None, []) for t in tests]
- all_tests = [] # type: T.List[TestDef]
- for t in test_defs:
+
+def load_test_json(t: TestDef, stdout_mandatory: bool) -> T.List[TestDef]:
+ all_tests: T.List[TestDef] = []
test_def = {}
test_def_file = t.path / 'test.json'
if test_def_file.is_file():
@@ -669,8 +666,9 @@ def gather_tests(testdir: Path, stdout_mandatory: bool) -> T.List[TestDef]:
t.installed_files = installed
t.do_not_set_opts = do_not_set_opts
t.stdout = stdout
- all_tests += [t]
- continue
+ return [t]
+
+ new_opt_list: T.List[T.List[T.Tuple[str, bool]]]
# 'matrix; entry is present, so build multiple tests from matrix definition
opt_list = [] # type: T.List[T.List[T.Tuple[str, bool]]]
@@ -705,7 +703,7 @@ def gather_tests(testdir: Path, stdout_mandatory: bool) -> T.List[TestDef]:
tmp_opts += [('{}={}'.format(key, i['val']), skip)]
if opt_list:
- new_opt_list = [] # type: T.List[T.List[T.Tuple[str, bool]]]
+ new_opt_list = []
for i in opt_list:
for j in tmp_opts:
new_opt_list += [[*i, j]]
@@ -716,7 +714,7 @@ def gather_tests(testdir: Path, stdout_mandatory: bool) -> T.List[TestDef]:
# Exclude specific configurations
if 'exclude' in matrix:
assert isinstance(matrix['exclude'], list)
- new_opt_list = [] # type: T.List[T.List[T.Tuple[str, bool]]]
+ new_opt_list = []
for i in opt_list:
exclude = False
opt_names = [x[0] for x in i]
@@ -740,10 +738,22 @@ def gather_tests(testdir: Path, stdout_mandatory: bool) -> T.List[TestDef]:
test.installed_files = installed
test.do_not_set_opts = do_not_set_opts
test.stdout = stdout
- all_tests += [test]
+ all_tests.append(test)
+
+ return all_tests
+
+
+def gather_tests(testdir: Path, stdout_mandatory: bool) -> T.List[TestDef]:
+ tests = [t.name for t in testdir.iterdir() if t.is_dir()]
+ tests = [t for t in tests if not t.startswith('.')] # Filter non-tests files (dot files, etc)
+ test_defs = [TestDef(testdir / t, None, []) for t in tests]
+ all_tests: T.List[TestDef] = []
+ for t in test_defs:
+ all_tests.extend(load_test_json(t, stdout_mandatory))
return sorted(all_tests)
+
def have_d_compiler():
if shutil.which("ldc2"):
return True
