diff --git a/meson_options.txt b/meson_options.txt index 49b298b..025f9ad 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,3 +1,3 @@ option('documentation', type: 'array', value: [], choices: ['api', 'protocol'], description: 'Enable documentation builds') -option('tests', type: 'boolean', value: 'true', description: 'Enable/disable tests') +option('tests', type: 'feature', value: 'auto', description: 'Enable/disable tests') option('liboeffis', type: 'feature', value: 'auto', description: 'Build liboeffis.so') diff --git a/test/meson.build b/test/meson.build index 5fc1fc1..6a82c38 100644 --- a/test/meson.build +++ b/test/meson.build @@ -1,4 +1,5 @@ -if not get_option('tests') +if get_option('tests').disabled() + summary({'Test suite enabled': false}, section: 'Test options') subdir_done() endif @@ -41,25 +42,6 @@ test('unit-tests-eis', c_args: ['-D_enable_tests_'], dependencies: [dep_unittest, dep_libutil])) -pymod = import('python') -required_python_modules = ['pytest', 'attr', 'structlog'] -if build_oeffis - required_python_modules += ['dbusmock'] -endif -python = pymod.find_installation('python3', modules: required_python_modules) -if python.language_version().version_compare('< 3.11') - pymod.find_installation('python3', modules: ['strenum']) -endif - -pytest = find_program('pytest-3', 'pytest') -pytest_args = ['--verbose', '--log-level=DEBUG'] - -optional_python_modules = ['xdist'] -if pymod.find_installation('python3', modules: optional_python_modules, required: false).found() - pytest_args += ['-n', 'auto'] - configure_file(input: 'conftest.py', output: '@PLAINNAME@', copy: true) -endif - if build_oeffis test('unit-tests-oeffis', executable('unit-tests-oeffis', @@ -68,15 +50,6 @@ if build_oeffis include_directories: [inc_src, inc_builddir], c_args: ['-D_enable_tests_'], dependencies: deps_liboeffis + [dep_unittest])) - - env = environment() - env.set('LD_LIBRARY_PATH', fs.parent(lib_liboeffis.full_path())) - test('oeffis-pytest', pytest, - args: pytest_args, - suite: 'python', - workdir: meson.current_source_dir(), - env: env, - ) endif lib_eierpecken = static_library('eierpecken', @@ -133,31 +106,77 @@ if add_languages('cpp', required: false) install: false) endif -eiproto_python_template = files('eiproto.py.tmpl') -eiproto_python = custom_target('eiproto.py', - input: protocol_xml, - output: 'eiproto.py', - command: [scanner, '--component=ei', '--output=@OUTPUT@', '@INPUT@', eiproto_python_template], - build_by_default: true) +# Python-based tests -protocol_test_config = configuration_data() -protocol_test_config.set('LIBEI_TEST_SERVER', eis_demo_server.full_path()) -configure_file(input: 'test_protocol.py', - output: '@PLAINNAME@', - configuration: protocol_test_config) +pymod = import('python') +required_python_modules = ['pytest', 'attr', 'structlog'] +python = pymod.find_installation('python3', required: get_option('tests')) +if python.found() and python.language_version().version_compare('< 3.11') + required_python_modules += ['strenum'] +endif +if build_oeffis + required_python_modules += ['dbusmock'] +endif -test('protocol-test', pytest, - args: pytest_args, - suite: 'python', - workdir: meson.project_build_root(), -) -if valgrind.found() - env = environment() - env.set('LIBEI_USE_VALGRIND', '1') - test('protocol-test-valgrind', pytest, +python = pymod.find_installation('python3', + modules: required_python_modules, + required: get_option('tests')) +pytest = find_program('pytest-3', 'pytest', required: get_option('tests')) +pytest_args = ['--verbose', '--log-level=DEBUG'] + +enable_pytest = python.found() and pytest.found() + +if enable_pytest + # pytest xdist is nice because it significantly speeds up our + # test process, but it's not required + optional_python_modules = ['xdist'] + if pymod.find_installation('python3', modules: optional_python_modules, required: false).found() + pytest_args += ['-n', 'auto'] + configure_file(input: 'conftest.py', output: '@PLAINNAME@', copy: true) + endif + + eiproto_python_template = files('eiproto.py.tmpl') + eiproto_python = custom_target('eiproto.py', + input: protocol_xml, + output: 'eiproto.py', + command: [scanner, '--component=ei', '--output=@OUTPUT@', '@INPUT@', eiproto_python_template], + build_by_default: true) + + protocol_test_config = configuration_data() + protocol_test_config.set('LIBEI_TEST_SERVER', eis_demo_server.full_path()) + configure_file(input: 'test_protocol.py', + output: '@PLAINNAME@', + configuration: protocol_test_config) + + test('protocol-test', pytest, args: pytest_args, suite: 'python', workdir: meson.project_build_root(), - env: env ) + if valgrind.found() + env = environment() + env.set('LIBEI_USE_VALGRIND', '1') + test('protocol-test-valgrind', pytest, + args: pytest_args, + suite: 'python', + workdir: meson.project_build_root(), + env: env + ) + endif + + if build_oeffis + env = environment() + env.set('LD_LIBRARY_PATH', fs.parent(lib_liboeffis.full_path())) + test('oeffis-pytest', pytest, + args: pytest_args, + suite: 'python', + workdir: meson.current_source_dir(), + env: env, + ) + endif endif + +summary({'valgrind available': valgrind.found(), + 'unit tests enabled': true, + 'pytest tests enabled': enable_pytest, + }, section: 'Test options')