diff --git a/scripts/check_no_game_data.py b/scripts/check_no_game_data.py index 92097253c5..ba6aa6ca6e 100644 --- a/scripts/check_no_game_data.py +++ b/scripts/check_no_game_data.py @@ -2,6 +2,7 @@ python3 -I scripts/check_no_game_data.py # every file `git ls-files` lists python3 -I scripts/check_no_game_data.py PATH... # only these files + python3 -I scripts/check_no_game_data.py --help # this text Explicit PATH inputs must be regular files, not directories or symlinks. A missing, unreadable or non-regular explicit input is reported on stderr and causes exit 2 unless another input matches game data (exit 1). @@ -312,6 +313,9 @@ def display(path): def main(argv): + if argv and argv[0] in ("-h", "--help"): + print(__doc__.strip()) + return 0 if argv: paths = argv else: diff --git a/scripts/play-linux.sh b/scripts/play-linux.sh index e7d48d78ea..5559f5f66b 100755 --- a/scripts/play-linux.sh +++ b/scripts/play-linux.sh @@ -10,8 +10,20 @@ # is changed. LEONIDA_* variables already set win over the defaults below. set -eu +usage() { + echo "usage: $0 /path/to/game_scarlett_master.exe [--series-x]" + echo + echo "LEONIDA_GAME_DIR, LEONIDA_CACHE_DIR and LEONIDA_DATA_DIR place the title's files, the caches and the saves;" + echo "LEONIDA_RUNTIME, LEONIDA_VKD3D and LEONIDA_WINEPREFIX choose the runtime, the bundled VKD3D-Proton and" + echo "the Wine prefix." +} + +if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then + usage + exit 0 +fi if [ $# -lt 1 ]; then - echo "usage: $0 /path/to/game_scarlett_master.exe [--series-x]" >&2 + usage >&2 exit 2 fi game_exe=$1 diff --git a/scripts/run_game_wine.sh b/scripts/run_game_wine.sh index cc60d67670..af4a5f399e 100755 --- a/scripts/run_game_wine.sh +++ b/scripts/run_game_wine.sh @@ -12,7 +12,7 @@ SELF=$ROOT/scripts/run_game_wine.sh usage() { cat <<'EOF' -Usage: scripts/run_game_wine.sh --build DIR --exe FILE --game-dir DIR --out DIR [options] [-- gta6rt arguments] +Usage: scripts/run_game_wine.sh --build DIR --exe FILE --game-dir DIR --shaders DIR --out DIR [options] [-- gta6rt arguments] Runs `gta6rt.exe --run ` once under Wine, headless or on this display, with sound off, a pinned Vulkan device, a time limit and the startup and D3D12 traces on, then prints counts only. Every path comes from here or from the diff --git a/scripts/run_wine_session.sh b/scripts/run_wine_session.sh index 437e18c3cb..2b75db124f 100755 --- a/scripts/run_wine_session.sh +++ b/scripts/run_wine_session.sh @@ -5,6 +5,13 @@ # run_wine_tests.py does, so Proton's or UMU-Proton's files/bin/wine also works on a host without a # system Wine. The wineserver is $WINESERVER, else the one next to $WINE, else wineserver on PATH. set -e +if [[ ${1:-} == -h || ${1:-} == --help ]]; then + echo "usage: run_wine_session.sh COMMAND [ARG...]" + echo + echo "Runs COMMAND on the display that initialized the dedicated Wine prefix in WINEPREFIX, then stops that" + echo "prefix's Wine processes. WINE (default wine) and WINESERVER (default: the one next to WINE) choose the Wine." + exit 0 +fi : "${WINEPREFIX:?Set WINEPREFIX to a dedicated test prefix}" wine=${WINE:-wine} diff --git a/tests/test_check_no_game_data.py b/tests/test_check_no_game_data.py index e00d0ff0cf..93bea4fa60 100644 --- a/tests/test_check_no_game_data.py +++ b/tests/test_check_no_game_data.py @@ -215,6 +215,15 @@ def write(self, name, data): f.write(data) return path + def test_help_prints_the_usage_and_checks_nothing(self): + for flag in ("-h", "--help"): + with self.subTest(flag=flag): + result = run([flag]) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertIn("python3 -I scripts/check_no_game_data.py PATH...", result.stdout) + self.assertIn("exits 2", result.stdout) + self.assertEqual(result.stderr, "") + def test_each_format_is_caught_under_another_name(self): for name, data, fmt in CAUGHT: with self.subTest(name=name): diff --git a/tests/test_play_linux.py b/tests/test_play_linux.py new file mode 100644 index 0000000000..2a22a28c2d --- /dev/null +++ b/tests/test_play_linux.py @@ -0,0 +1,34 @@ +"""scripts/play-linux.sh answers --help with its usage, without a game executable, Wine or a prefix. + + python -I tests/test_play_linux.py + +The help path is checked alone: PATH holds nothing but the shell, and no LEONIDA_* variable is set, so a --help that +fell through to the game start would fail loudly instead of passing. POSIX only; no game files. +""" +import os +import shutil +import subprocess +import unittest +from pathlib import Path + +SCRIPT = Path(__file__).resolve().parents[1] / "scripts" / "play-linux.sh" + + +@unittest.skipUnless(os.name == "posix" and shutil.which("sh"), "needs a POSIX shell") +class PlayLinuxHelp(unittest.TestCase): + def run_help(self, flag: str) -> subprocess.CompletedProcess: + return subprocess.run(["sh", str(SCRIPT), flag], env={"PATH": "/usr/bin:/bin"}, + capture_output=True, text=True, timeout=60) + + def test_help_prints_the_usage_and_starts_nothing(self): + for flag in ("-h", "--help"): + with self.subTest(flag=flag): + p = self.run_help(flag) + self.assertEqual(p.returncode, 0, p.stderr) + self.assertIn("usage:", p.stdout) + self.assertIn("--series-x", p.stdout) + self.assertEqual(p.stderr, "") + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/test_run_game_wine.py b/tests/test_run_game_wine.py index 7dd976ffce..68fac68aa6 100644 --- a/tests/test_run_game_wine.py +++ b/tests/test_run_game_wine.py @@ -107,6 +107,8 @@ def test_help_lists_the_inputs(self): "--screenshot-every", "LEONIDA_SHADERS", "LEONIDA_GAME_EXE", "LEONIDA_AUDIO=silent", "kwin_wayland", "DRI3"): self.assertIn(word, p.stdout) + # The Usage line itself names every required input, not just the Inputs section below it. + self.assertIn("--shaders", p.stdout.splitlines()[0]) def test_a_missing_input_is_named(self): for flag, word in (("--build", "--build is required"), ("--exe", "--exe (or LEONIDA_GAME_EXE)"), diff --git a/tests/test_run_wine_session.py b/tests/test_run_wine_session.py index 4d79348fd4..cf5746e8c7 100644 --- a/tests/test_run_wine_session.py +++ b/tests/test_run_wine_session.py @@ -62,6 +62,15 @@ def test_wineserver_override_and_path_fallback(self): self.assertEqual(r.returncode, 0, r.stderr) self.assertEqual(log.read_text().splitlines()[-1], f"{other / 'my-wineserver'} -k") + def test_help_needs_no_prefix_or_wine(self): + for flag in ("-h", "--help"): + with self.subTest(flag=flag): + r = subprocess.run(["bash", str(SCRIPT), flag], env={"PATH": "/usr/bin:/bin"}, + capture_output=True, text=True, timeout=60) + self.assertEqual(r.returncode, 0, r.stderr) + self.assertIn("WINEPREFIX", r.stdout) + self.assertEqual(r.stderr, "") + def test_missing_wine_is_reported(self): with tempfile.TemporaryDirectory() as d: root = Path(d)