# SPDX-License-Identifier: MIT """The GPL tools are found only at their documented paths (emu-tools docs/contract.md, section 5). Without ``EMU_TOOLS_GPL`` (or with the tool absent under it) a script that needs a tool stops with exit status 3, a missing input, and names the variable. Nothing here runs a tool. """ import os import subprocess import sys from pathlib import Path import pytest ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / "scripts")) import emu_tools # noqa: E402 def test_paths_are_the_documented_ones(): assert emu_tools.MESEN2_RUN == ("EMU_TOOLS_GPL", "tools/mesen2/run.py") assert emu_tools.SPC_DUMP == ("EMU_TOOLS_GPL", "tools/snes-spc/build/spc_dump") assert "tools/snes-spc/build.sh" in emu_tools.why_missing(emu_tools.SPC_DUMP) def test_unset_or_absent_is_a_missing_input(monkeypatch, tmp_path, capsys): monkeypatch.delenv("EMU_TOOLS_GPL", raising=False) assert emu_tools.find(emu_tools.MESEN2_RUN) is None with pytest.raises(SystemExit) as stop: emu_tools.require(emu_tools.MESEN2_RUN) assert stop.value.code == 3 assert "EMU_TOOLS_GPL" in capsys.readouterr().err monkeypatch.setenv("EMU_TOOLS_GPL", str(tmp_path)) # a checkout without the tool assert emu_tools.find(emu_tools.MESEN2_RUN) is None assert "does not exist" in emu_tools.why_missing(emu_tools.MESEN2_RUN) (tmp_path / "tools" / "mesen2").mkdir(parents=True) (tmp_path / "tools" / "mesen2" / "run.py").write_text("") assert emu_tools.find(emu_tools.MESEN2_RUN) == tmp_path / "tools" / "mesen2" / "run.py" def test_a_script_exits_3_without_the_variable(): env = {k: v for k, v in os.environ.items() if k != "EMU_TOOLS_GPL"} done = subprocess.run( [sys.executable, "-I", str(ROOT / "scripts" / "dsp_build_referees.py")], capture_output=True, text=True, env=env, check=False, ) # fmt: skip assert done.returncode == 3 assert "EMU_TOOLS_GPL" in done.stderr