mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 09:08:38 +00:00
scripts: --help on the Python and shell entry points
check_no_game_data.py read `--help` as a path and answered "cannot read --help", exit 2, in the tool every contributor is told to run; it now prints the usage text it already carries and exits 0. play-linux.sh and run_wine_session.sh print their usage before any environment check, where they used to answer with an error (and play-linux.sh's no-argument case still prints the same usage, on stderr, exit 2). run_game_wine.sh's one-line Usage line names the required --shaders, which its Inputs section already listed. A test per script fails on main's copies and passes here.
This commit is contained in:
@ -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:
|
||||
|
||||
@ -10,8 +10,19 @@
|
||||
# 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_RUNTIME, LEONIDA_VKD3D and LEONIDA_WINEPREFIX choose the runtime, the bundled VKD3D-Proton and"
|
||||
echo "the Wine prefix; LEONIDA_CACHE_DIR and LEONIDA_DATA_DIR the caches and saves."
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@ -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 <exe>` 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
|
||||
|
||||
@ -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}
|
||||
|
||||
@ -215,6 +215,13 @@ class CheckNoGameData(unittest.TestCase):
|
||||
f.write(data)
|
||||
return path
|
||||
|
||||
def test_help_prints_the_usage_and_checks_nothing(self):
|
||||
result = run(["--help"])
|
||||
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):
|
||||
|
||||
34
tests/test_play_linux.py
Normal file
34
tests/test_play_linux.py
Normal file
@ -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()
|
||||
@ -107,6 +107,8 @@ class RunGameWineTest(unittest.TestCase):
|
||||
"--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)"),
|
||||
|
||||
@ -62,6 +62,13 @@ class WineSessionTests(unittest.TestCase):
|
||||
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):
|
||||
r = subprocess.run(["bash", str(SCRIPT), "--help"], 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)
|
||||
|
||||
Reference in New Issue
Block a user