mirror of
https://github.com/Cesarus85/ringfall-mjolnir-vr.git
synced 2026-10-23 05:00:32 +02:00
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
"""Runs the C tests of the menus' touch gestures (port/linux/src/touch_menu.c)
|
|
with the build machine's C compiler. The unit has no SDL or game
|
|
dependency, so it compiles anywhere."""
|
|
import shutil
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
|
|
|
|
def compiler():
|
|
"""Finds a C compiler on the build machine.
|
|
|
|
Returns the path of clang, cc or gcc (the first found), or None.
|
|
"""
|
|
for name in ("clang", "cc", "gcc"):
|
|
path = shutil.which(name)
|
|
if path:
|
|
return path
|
|
return None
|
|
|
|
|
|
def test_touch_menu(tmp_path):
|
|
"""Builds the gesture unit with its tests, warnings as errors, and runs them."""
|
|
cc = compiler()
|
|
if not cc:
|
|
pytest.skip("no C compiler")
|
|
binary = tmp_path / "touch_menu_test"
|
|
build = subprocess.run(
|
|
[cc, "-std=c11", "-Wall", "-Wextra", "-Werror", "-O1",
|
|
str(ROOT / "port" / "linux" / "tests" / "touch_menu_test.c"),
|
|
str(ROOT / "port" / "linux" / "src" / "touch_menu.c"),
|
|
"-lm", "-o", str(binary)],
|
|
capture_output=True, text=True,
|
|
)
|
|
assert build.returncode == 0, build.stdout + build.stderr
|
|
result = subprocess.run([str(binary)], capture_output=True, text=True)
|
|
assert result.returncode == 0, result.stdout + result.stderr
|