test_install_script.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from __future__ import annotations
  2. import subprocess
  3. from pathlib import Path
  4. REPO_ROOT = Path(__file__).resolve().parents[1]
  5. INSTALL_SCRIPT = REPO_ROOT / "scripts" / "install.sh"
  6. def test_detect_os_does_not_override_install_version(tmp_path: Path) -> None:
  7. """Regression test for #1753 on Ubuntu 24.04 fresh installs."""
  8. os_release = tmp_path / "os-release"
  9. os_release.write_text(
  10. 'ID=ubuntu\nVERSION_ID="24.04"\nVERSION="24.04.4 LTS (Noble Numbat)"\n',
  11. encoding="utf-8",
  12. )
  13. command = f"""
  14. source "{INSTALL_SCRIPT}"
  15. INSTALL_VERSION="latest"
  16. VERSION="latest"
  17. OSTYPE="linux-gnu"
  18. OS_RELEASE_FILE="{os_release}"
  19. detect_os
  20. printf '%s\\n%s\\n%s\\n' "$INSTALL_VERSION" "$DISTRO_ID" "$DISTRO_VERSION"
  21. """
  22. result = subprocess.run(
  23. ["bash", "-lc", command],
  24. cwd=REPO_ROOT,
  25. capture_output=True,
  26. text=True,
  27. check=False,
  28. )
  29. assert result.returncode == 0, result.stderr
  30. assert result.stdout.splitlines() == ["latest", "ubuntu", "24.04"]
  31. def test_install_script_runs_from_stdin_with_nounset() -> None:
  32. """Regression test for stdin execution via `curl ... | bash`."""
  33. result = subprocess.run(
  34. ["bash", "-s", "--", "--help"],
  35. cwd=REPO_ROOT,
  36. input=INSTALL_SCRIPT.read_text(encoding="utf-8"),
  37. capture_output=True,
  38. text=True,
  39. check=False,
  40. )
  41. assert result.returncode == 0, result.stderr
  42. assert "Install the boilerplates CLI from GitHub releases via pipx." in result.stdout