test(install): simulate a Linux uname for install.sh Linux-behaviour tests
(cherry picked from commit f8b2acd580bc86b8257ab71705c1ea2189fdf675)
This commit is contained in:
27
tests/scripts/install/_linux_host.py
Normal file
27
tests/scripts/install/_linux_host.py
Normal file
@@ -0,0 +1,27 @@
|
||||
"""Let install.sh's platform gate see a Linux host on any test host.
|
||||
|
||||
``check_platform`` refuses anything but Linux/macOS by ``uname -s`` (Git Bash on Windows
|
||||
reports ``MINGW64_NT-…`` and is sent to install.ps1, as it should be). Tests of Linux
|
||||
install behaviour that is not about the host itself put this ``uname`` first on PATH;
|
||||
every query other than ``-s`` still answers from the real ``uname``.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
_UNAME = """#!/bin/sh
|
||||
case "$*" in -s) echo Linux; exit 0 ;; esac
|
||||
# This shim's directory is the first PATH entry; drop it to reach the real uname.
|
||||
PATH="${PATH#*:}" exec uname "$@"
|
||||
"""
|
||||
|
||||
|
||||
def linux_uname_path(tmp_path: Path, path: str) -> str:
|
||||
"""Return ``path`` with a directory holding a Linux-reporting ``uname`` prepended."""
|
||||
bindir = tmp_path / "linux-uname"
|
||||
bindir.mkdir()
|
||||
uname = bindir / "uname"
|
||||
uname.write_text(_UNAME, encoding="utf-8", newline="\n")
|
||||
uname.chmod(0o755)
|
||||
return str(bindir) + os.pathsep + path
|
||||
@@ -17,6 +17,8 @@ from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.scripts.install._linux_host import linux_uname_path
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parent.parent.parent.parent
|
||||
INSTALL_SH = REPO_ROOT / "scripts" / "install.sh"
|
||||
INSTALL_PS1 = REPO_ROOT / "scripts" / "install.ps1"
|
||||
@@ -75,6 +77,8 @@ def test_install_sh_repository_stage_parks_local_commits_before_reset(tmp_path:
|
||||
env = os.environ | {
|
||||
"HERMES_HOME": str(tmp_path / "hermes-home"),
|
||||
"HERMES_INSTALL_DIR": str(managed),
|
||||
# The reset under test is host-independent; only the platform gate reads the OS.
|
||||
"PATH": linux_uname_path(tmp_path, os.environ["PATH"]),
|
||||
}
|
||||
|
||||
result = subprocess.run(
|
||||
|
||||
@@ -5,6 +5,8 @@ import subprocess
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.scripts.install._linux_host import linux_uname_path
|
||||
|
||||
INSTALL_SH = Path(__file__).resolve().parent.parent.parent.parent / "scripts" / "install.sh"
|
||||
|
||||
|
||||
@@ -23,7 +25,7 @@ def test_termux_host_is_refused_before_any_stage_with_apt_hint(tmp_path, marker)
|
||||
def test_plain_linux_host_passes_platform_check(tmp_path):
|
||||
env = {k: v for k, v in os.environ.items() if k not in ("TERMUX_VERSION", "PREFIX")}
|
||||
env.update(HOME=tmp_path.as_posix(), HERMES_HOME=(tmp_path / "home").as_posix(),
|
||||
HERMES_INSTALL_DIR=(tmp_path / "install").as_posix())
|
||||
HERMES_INSTALL_DIR=(tmp_path / "install").as_posix(), PATH=linux_uname_path(tmp_path, env["PATH"]))
|
||||
result = subprocess.run(["bash", INSTALL_SH.as_posix(), "--stage", "prerequisites"],
|
||||
env=env, capture_output=True, text=True, timeout=30, check=False)
|
||||
assert result.returncode == 0, result.stderr
|
||||
|
||||
Reference in New Issue
Block a user