summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2020-06-18 17:47:46 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2020-06-22 00:22:25 +0000
commit118178208e6aebea5b9c85edb752a50e82bb3144 (patch)
treed1e4e013c96feb07553eb5b9b7568186b885f8e1 /tests
parent0d5193783cb24ece2c36c1830dc65358c6bd7424 (diff)
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 <peter.hutterer@who-t.net>
Diffstat (limited to 'tests')
-rw-r--r--tests/__init__.py0
-rw-r--r--tests/test_xkb_symbols.py78
2 files changed, 78 insertions, 0 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/__init__.py
diff --git a/tests/test_xkb_symbols.py b/tests/test_xkb_symbols.py
new file mode 100644
index 00000000..e3d507ce
--- /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