Skip to content

Commit

Permalink
tests: Clean up leftover files from source dirs.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpakkane authored Jul 10, 2024
1 parent 9a60def commit 47fd13a
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 4 deletions.
6 changes: 6 additions & 0 deletions data/test.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@
"items": {
"type": "string"
}
},
"cleanup": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
6 changes: 3 additions & 3 deletions mesonbuild/utils/universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1788,7 +1788,7 @@ def get_filenames_templates_dict(inputs: T.List[str], outputs: T.List[str]) -> T
return values


def _make_tree_writable(topdir: str) -> None:
def _make_tree_writable(topdir: T.Union[str, Path]) -> None:
# Ensure all files and directories under topdir are writable
# (and readable) by owner.
for d, _, files in os.walk(topdir):
Expand All @@ -1799,7 +1799,7 @@ def _make_tree_writable(topdir: str) -> None:
os.chmod(fpath, os.stat(fpath).st_mode | stat.S_IWRITE | stat.S_IREAD)


def windows_proof_rmtree(f: str) -> None:
def windows_proof_rmtree(f: T.Union[str, Path]) -> None:
# On Windows if anyone is holding a file open you can't
# delete it. As an example an anti virus scanner might
# be scanning files you are trying to delete. The only
Expand All @@ -1826,7 +1826,7 @@ def windows_proof_rmtree(f: str) -> None:
shutil.rmtree(f)


def windows_proof_rm(fpath: str) -> None:
def windows_proof_rm(fpath: T.Union[str, Path]) -> None:
"""Like windows_proof_rmtree, but for a single file."""
if os.path.isfile(fpath):
os.chmod(fpath, os.stat(fpath).st_mode | stat.S_IWRITE | stat.S_IREAD)
Expand Down
15 changes: 14 additions & 1 deletion run_project_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ def __init__(self, path: Path, name: T.Optional[str], args: T.List[str], skip: b
self.stdout: T.List[T.Dict[str, str]] = []
self.skip_category = skip_category
self.skip_expected = False
self.cleanup: T.List[str] = []

# Always print a stack trace for Meson exceptions
self.env['MESON_FORCE_BACKTRACE'] = '1'
Expand Down Expand Up @@ -844,6 +845,8 @@ def load_test_json(t: TestDef, stdout_mandatory: bool, skip_category: bool = Fal

(t.skip, t.skip_expected) = _skip_keys(test_def)

cleanup = test_def.get('cleanup', [])

# Skip tests if the tool requirements are not met
if 'tools' in test_def:
assert isinstance(test_def['tools'], dict)
Expand All @@ -859,6 +862,7 @@ def load_test_json(t: TestDef, stdout_mandatory: bool, skip_category: bool = Fal
t.installed_files = installed
t.do_not_set_opts = do_not_set_opts
t.stdout = stdout
t.cleanup = cleanup
return [t]

new_opt_list: T.List[T.List[T.Tuple[str, str, bool, bool]]]
Expand Down Expand Up @@ -928,6 +932,8 @@ def load_test_json(t: TestDef, stdout_mandatory: bool, skip_category: bool = Fal
test.do_not_set_opts = do_not_set_opts
test.stdout = stdout
test.skip_expected = skip_expected or t.skip_expected
test.cleanup = cleanup

all_tests.append(test)

return all_tests
Expand Down Expand Up @@ -1393,6 +1399,13 @@ def tqdm_print(*args: mlog.TV_Loggable, sep: str = ' ') -> None:
else:
f.update_log(TestStatus.OK)
passing_tests += 1
for cleanup_path in t.cleanup:
assert not os.path.isabs(cleanup_path)
abspath = t.path / cleanup_path
if abspath.is_file():
mesonlib.windows_proof_rm(abspath)
else:
mesonlib.windows_proof_rmtree(abspath)
conf_time += result.conftime
build_time += result.buildtime
test_time += result.testtime
Expand Down Expand Up @@ -1550,7 +1563,7 @@ def get_version(t: ToolInfo) -> str:
print()

tmpdir = list(Path('.').glob('test cases/**/*install functions and follow symlinks'))
assert(len(tmpdir) == 1)
assert len(tmpdir) == 1
symlink_test_dir = tmpdir[0]
symlink_file1 = symlink_test_dir / 'foo/link1'
symlink_file2 = symlink_test_dir / 'foo/link2.h'
Expand Down
3 changes: 3 additions & 0 deletions test cases/common/153 wrap file should not failed/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cleanup": ["subprojects/foo-1.0-patchfile"]
}
3 changes: 3 additions & 0 deletions test cases/common/258 subsubproject inplace/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cleanup": ["subprojects/subsub.wrap"]
}
3 changes: 3 additions & 0 deletions test cases/rust/25 cargo lock/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cleanup": ["subprojects/bar-0.1"]
}

0 comments on commit 47fd13a

Please sign in to comment.