import json
from pathlib import Path
from conftest import get_bin_path, run_clyde, run_in_clyde_home
def test_install_pinned_version(clyde_home):
run_clyde("install", "starship@=1.10.2")
bin_path = get_bin_path("starship")
assert bin_path.exists()
result = run_in_clyde_home("starship --version")
assert "starship 1.10.2" in result.stdout
def test_uninstall_package(clyde_home):
starship_path = get_bin_path("starship")
run_clyde("install", "starship")
assert starship_path.exists()
run_clyde("uninstall", "starship")
assert not starship_path.exists()
def test_reinstall_package(clyde_home):
starship_path = get_bin_path("starship")
run_clyde("install", "starship")
assert starship_path.exists()
starship_path.unlink()
assert not starship_path.exists()
run_clyde("install", "--reinstall", "starship")
assert starship_path.exists()
def test_install_cleans_after_itself_in_case_of_failure(clyde_home):
run_clyde("install", "glab")
xh_info = json.loads(run_clyde("show", "-l", "--json", "glab").stdout)
paths = [Path(x) for x in xh_info["files"]]
run_clyde("uninstall", "glab")
for idx, existing_path in enumerate(paths):
existing_path.write_text("foo")
other_paths = paths[:idx] + paths[idx + 1:]
proc = run_clyde("install", "glab", check=False)
assert proc.returncode != 0
for other_path in other_paths:
assert not other_path.exists(), f"{existing_path=} {other_paths=}"
assert existing_path.read_text() == "foo"
existing_path.unlink()