From 118178208e6aebea5b9c85edb752a50e82bb3144 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 18 Jun 2020 17:47:46 +1000 Subject: tests: add a test to compile all xkb_symbols section with xkbcomp Using pytest because it does a lot of the setup/tracing stuff for us. The test checks all symbols files and generates a list of tuples (layout, variant) from the files. That's then used in a generic-enough keymap to be fed to xkbcomp. Where xkbcomp fails we fail the test (and pytest will collect stdout/stderr/etc.) for us. Signed-off-by: Peter Hutterer --- tests/__init__.py | 0 tests/test_xkb_symbols.py | 78 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 tests/__init__.py create mode 100644 tests/test_xkb_symbols.py (limited to 'tests') diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_xkb_symbols.py b/tests/test_xkb_symbols.py new file mode 100644 index 0000000..e3d507c --- /dev/null +++ b/tests/test_xkb_symbols.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python3 +# +# Call with pytest. Requires XKB_CONFIG_ROOT to be set + +import os +import pytest +import subprocess +import sys +from pathlib import Path + + +def _xkb_config_root(): + path = os.getenv('XKB_CONFIG_ROOT') + assert path is not None, 'Environment variable XKB_CONFIG_ROOT must be set' + print(f'Using {path}') + + xkbpath = Path(path) + assert (xkbpath / 'symbols').exists(), f'{path} is not an XKB installation' + return xkbpath + + +@pytest.fixture +def xkb_config_root(): + return _xkb_config_root() + + +def pytest_generate_tests(metafunc): + # for any test_foo function with an argument named xkb_symbols, + # make it a list of tuples in the form (us, dvorak) + # The list is generated by scanning all xkb symbol files and extracting the + # various sections + if 'xkb_symbols' in metafunc.fixturenames: + + xkb_symbols = [] + # This skips the *_vndr directories, they're harder to test + for symbols_file in _xkb_config_root().glob('symbols/*'): + if symbols_file.is_dir(): + continue + with open(symbols_file) as f: + print(f'Found file {symbols_file}') + for line in f: + if not line.startswith('xkb_symbols "'): + continue + section = line.split('"')[1] + xkb_symbols.append((symbols_file.name, section)) + assert xkb_symbols + metafunc.parametrize('xkb_symbols', xkb_symbols) + + +def test_xkbcomp(xkb_config_root, xkb_symbols): + layout, variant = xkb_symbols + keymap = ''' +xkb_keymap { + xkb_keycodes { include "evdev+aliases(qwerty)" }; + xkb_types { include "complete" }; + xkb_compat { include "complete" }; + xkb_symbols { include "pc+%s(%s)" }; +}; +''' % (layout, variant) + print(keymap) + + args = [ + 'xkbcomp', + '-w0', # reduce warning nose + '-xkb', + '-I', # disable system includes + f'-I{xkb_config_root}', + '-', '-', # from stdin, to stdout + ] + p = subprocess.run(args, input=keymap, encoding='utf-8', capture_output=True) + if p.stderr: + print(p.stderr, file=sys.stderr) + if p.returncode != 0: + print(p.stdout) + if p.returncode < 0: + print(f'xkbcomp exited with signal {-p.returncode}', file=sys.stderr) + + assert p.returncode == 0 -- cgit v1.2.1