"""Guard shell scripts in scripts/ against syntax regressions.""" from __future__ import annotations import shutil import subprocess from pathlib import Path import pytest REPO_ROOT = Path(__file__).resolve().parents[2] SCRIPTS = [ REPO_ROOT / "scripts" / "sim_cameras.sh", REPO_ROOT / "scripts" / "download_mediamtx.sh", ] @pytest.mark.parametrize("script", SCRIPTS, ids=lambda p: p.name) def test_script_exists(script: Path) -> None: assert script.is_file(), f"missing script: {script}" @pytest.mark.parametrize("script", SCRIPTS, ids=lambda p: p.name) def test_bash_syntax(script: Path) -> None: result = subprocess.run( ["bash", "-n", str(script)], capture_output=True, text=True, ) assert result.returncode == 0, f"bash -n failed:\n{result.stderr}" @pytest.mark.parametrize("script", SCRIPTS, ids=lambda p: p.name) def test_shellcheck(script: Path) -> None: if shutil.which("shellcheck") is None: pytest.skip("shellcheck not installed") result = subprocess.run( ["shellcheck", "--severity=warning", str(script)], capture_output=True, text=True, ) assert result.returncode == 0, f"shellcheck failed:\n{result.stdout}\n{result.stderr}"