Skip to content

Commit

Permalink
fix: support --uninstall for all clang-tools (#103)
Browse files Browse the repository at this point in the history
* fix: support uninstall all clang-tools

* fix: update tests

* fix: update tests

* fix: update python-test.yml
  • Loading branch information
shenxianpeng authored Aug 12, 2024
1 parent 7d78b27 commit 8d50cd8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ jobs:
shell: bash
run: |
case "${{ matrix.version }}" in
15|16)
15|16|18)
clang-format.exe --version
clang-tidy.exe --version
clang-query.exe --version
Expand Down
4 changes: 2 additions & 2 deletions clang_tools/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def uninstall_tool(tool_name: str, version: str, directory: str):
symlink.unlink()


def uninstall_clang_tools(version: str, directory: str):
def uninstall_clang_tools(tools: str, version: str, directory: str):
"""Uninstall a clang tool of a given version.
:param version: The version of the clang-tools to remove.
Expand All @@ -243,7 +243,7 @@ def uninstall_clang_tools(version: str, directory: str):
"""
install_dir = install_dir_name(directory)
print(f"Uninstalling version {version} from {str(install_dir)}")
for tool in ("clang-format", "clang-tidy"):
for tool in tools:
uninstall_tool(tool, version, install_dir)


Expand Down
2 changes: 1 addition & 1 deletion clang_tools/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def main():
args = parser.parse_args()

if args.uninstall:
uninstall_clang_tools(args.uninstall, args.directory)
uninstall_clang_tools(args.uninstall, args.tool, args.directory)
elif args.install:
version = Version(args.install)
if version.info != (0, 0, 0):
Expand Down
16 changes: 9 additions & 7 deletions tests/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,22 @@ def test_create_symlink(monkeypatch: pytest.MonkeyPatch, tmp_path: Path):
assert not create_sym_link(tool_name, version, str(tmp_path), True)


@pytest.mark.parametrize(
"tool_name",
["clang-format", "clang-tidy", "clang-query", "clang-apply-replacements"],
)
@pytest.mark.parametrize("version", ["12"])
def test_install_tools(monkeypatch: pytest.MonkeyPatch, tmp_path: Path, version: str):
def test_install_tools(
monkeypatch: pytest.MonkeyPatch, tmp_path: Path, tool_name: str, version: str
):
"""Test install tools to a temp directory."""
monkeypatch.chdir(tmp_path)
tool_name = "clang-format"

assert install_tool(tool_name, version, str(tmp_path), False)
# invoking again should return False
assert not install_tool(tool_name, version, str(tmp_path), False)
# uninstall the tool deliberately
uninstall_clang_tools(version, str(tmp_path))
assert f"{tool_name}-{version}{suffix}" not in [
fd.name for fd in tmp_path.iterdir()
]
uninstall_clang_tools(tool_name, version, str(tmp_path))
assert f"{tool_name}-{version}{suffix}" in [fd.name for fd in tmp_path.iterdir()]


@pytest.mark.parametrize("version", ["0"])
Expand Down

0 comments on commit 8d50cd8

Please sign in to comment.