diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index f50ce58ab..c05e30b46 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -51,7 +51,7 @@ jobs: run: | meson setup _build \ -Dinstalled-tests=true \ - -Dpytest=enabled \ + -Dtests=enabled \ -Db_sanitize=${{ matrix.sanitizer }} \ -Db_lundef=false meson compile -C _build diff --git a/meson.build b/meson.build index 90d3b9d98..4c7d7d751 100644 --- a/meson.build +++ b/meson.build @@ -121,7 +121,7 @@ geoclue_dep = dependency( pipewire_dep = dependency('libpipewire-0.3', version: '>= 0.2.90') libsystemd_dep = dependency('libsystemd', required: get_option('systemd')) gudev_dep = dependency('gudev-1.0', required: get_option('gudev')) -umockdev_dep = dependency('umockdev-1.0', required: get_option('pytest')) +umockdev_dep = dependency('umockdev-1.0', required: get_option('tests')) gst_inspect = find_program('gst-inspect-1.0', required: false) if gst_inspect.found() @@ -136,6 +136,13 @@ if have_wav_parse config_h.set('HAVE_WAV_PARSE', 1) endif +pytest = find_program('pytest-3', 'pytest', required: get_option('tests')) +python = pymod.find_installation( + 'python3', + modules: ['dbus', 'dbusmock', 'gi'], + required: get_option('tests'), +) + bwrap = find_program('bwrap', required: get_option('sandboxed-image-validation').allowed() or get_option('sandboxed-sound-validation').allowed()) if not bwrap.found() @@ -181,8 +188,6 @@ endif rst2man = find_program('rst2man', 'rst2man.py', required: get_option('man-pages')) -enable_installed_tests = get_option('installed-tests') - ###### systemd units, dbus service files, pkgconfig base_config = configuration_data() @@ -206,13 +211,29 @@ pkgconfig.generate( }, ) +###### subdirs + subdir('data') subdir('src') subdir('document-portal') -subdir('tests') subdir('po') subdir('doc') +enable_tests = get_option('tests') \ + .require(pytest.found()) \ + .require(python.found() and python.language_version().version_compare('>=3.9'), + error_message: 'Python version >=3.9 is required') \ + .require(umockdev_dep.found()) \ + .require(have_wav_parse, + error_message: 'gst-inspect and the wavparse plugins are required') \ + .allowed() + +enable_installed_tests = get_option('installed-tests') + +if enable_tests + subdir('tests') +endif + ###### generate config.h configure_file(output: 'config.h', configuration: config_h) @@ -221,8 +242,8 @@ summary({ 'Enable libsystemd support': have_libsystemd, 'Enable geoclue support': have_geoclue, 'Enable gudev support': have_gudev, + 'Enable test suite': enable_tests, 'Enable installed tests:': enable_installed_tests, - 'Enable python test suite': enable_pytest, 'Build man pages': rst2man.found(), 'Build flatpak interfaces': flatpak_intf_dir != '', 'Sandboxed image validation': bwrap.found(), diff --git a/meson_options.txt b/meson_options.txt index 5f2611317..ed8c31126 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -34,14 +34,14 @@ option('datarootdir', type: 'string', value: '', description: 'Define the datarootdir for the pkgconf file') +option('tests', + type: 'feature', + value: 'enabled', + description: 'Enable the test suite') option('installed-tests', type: 'boolean', value: false, description: 'Enable installation of some test cases') -option('pytest', - type: 'feature', - value: 'enabled', - description: 'Enable the pytest-based test suite') option('man-pages', type: 'feature', value: 'auto', diff --git a/tests/meson.build b/tests/meson.build index add23414c..fa26715c8 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -62,147 +62,129 @@ test( protocol: test_protocol, ) -pytest = find_program('pytest-3', 'pytest', required: get_option('pytest')) -python = pymod.find_installation( - 'python3', - modules: ['dbus', 'dbusmock', 'gi'], - required: get_option('pytest'), -) +pytest_args = ['--verbose', '--log-level=DEBUG'] + +pytest_env = environment() +pytest_env.set('XDG_DESKTOP_PORTAL_PATH', xdg_desktop_portal.full_path()) +pytest_env.set('XDG_PERMISSION_STORE_PATH', xdg_permission_store.full_path()) +pytest_env.set('XDG_DOCUMENT_PORTAL_PATH', xdg_document_portal.full_path()) +pytest_env.set('XDP_VALIDATE_ICON', xdp_validate_icon.full_path()) +pytest_env.set('XDP_VALIDATE_SOUND', xdp_validate_sound.full_path()) + +# pytest xdist is nice because it significantly speeds up our +# test process, but it's not required +if pymod.find_installation('python3', modules: ['xdist'], required: false).found() + # using auto can easily start too many tests which will block each other + # a value of around 5 seems to work well + pytest_args += ['-n', '5'] +endif -enable_pytest = get_option('pytest') \ - .require(pytest.found()) \ - .require(python.found() and python.language_version().version_compare('>=3.9'), - error_message: 'Python version >=3.9 is required') \ - .require(umockdev_dep.found()) \ - .require(have_wav_parse, - error_message: 'gst-inspect and the wavparse plugins are required') \ - .allowed() - -if enable_pytest - pytest_args = ['--verbose', '--log-level=DEBUG'] - - pytest_env = environment() - pytest_env.set('XDG_DESKTOP_PORTAL_PATH', xdg_desktop_portal.full_path()) - pytest_env.set('XDG_PERMISSION_STORE_PATH', xdg_permission_store.full_path()) - pytest_env.set('XDG_DOCUMENT_PORTAL_PATH', xdg_document_portal.full_path()) - pytest_env.set('XDP_VALIDATE_ICON', xdp_validate_icon.full_path()) - pytest_env.set('XDP_VALIDATE_SOUND', xdp_validate_sound.full_path()) - - # pytest xdist is nice because it significantly speeds up our - # test process, but it's not required - if pymod.find_installation('python3', modules: ['xdist'], required: false).found() - # using auto can easily start too many tests which will block each other - # a value of around 5 seems to work well - pytest_args += ['-n', '5'] - endif - - pytest_files = [ - 'test_account.py', - 'test_background.py', - 'test_camera.py', - 'test_clipboard.py', - 'test_documents.py', - 'test_document_fuse.py', - 'test_dynamiclauncher.py', - 'test_email.py', - 'test_filechooser.py', - 'test_globalshortcuts.py', - 'test_inhibit.py', - 'test_inputcapture.py', - 'test_location.py', - 'test_notification.py', - 'test_openuri.py', - 'test_permission_store.py', - 'test_print.py', - 'test_registry.py', - 'test_remotedesktop.py', - 'test_settings.py', - 'test_screenshot.py', - 'test_trash.py', - 'test_usb.py', - 'test_wallpaper.py', - ] - - template_files = [ - 'templates/access.py', - 'templates/account.py', - 'templates/appchooser.py', - 'templates/background.py', - 'templates/clipboard.py', - 'templates/dynamiclauncher.py', - 'templates/email.py', - 'templates/filechooser.py', - 'templates/geoclue2.py', - 'templates/globalshortcuts.py', - 'templates/inhibit.py', - 'templates/__init__.py', - 'templates/inputcapture.py', - 'templates/lockdown.py', - 'templates/notification.py', - 'templates/print.py', - 'templates/remotedesktop.py', - 'templates/screenshot.py', - 'templates/settings.py', - 'templates/usb.py', - 'templates/wallpaper.py', - ] +pytest_files = [ + 'test_account.py', + 'test_background.py', + 'test_camera.py', + 'test_clipboard.py', + 'test_documents.py', + 'test_document_fuse.py', + 'test_dynamiclauncher.py', + 'test_email.py', + 'test_filechooser.py', + 'test_globalshortcuts.py', + 'test_inhibit.py', + 'test_inputcapture.py', + 'test_location.py', + 'test_notification.py', + 'test_openuri.py', + 'test_permission_store.py', + 'test_print.py', + 'test_registry.py', + 'test_remotedesktop.py', + 'test_settings.py', + 'test_screenshot.py', + 'test_trash.py', + 'test_usb.py', + 'test_wallpaper.py', +] + +template_files = [ + 'templates/access.py', + 'templates/account.py', + 'templates/appchooser.py', + 'templates/background.py', + 'templates/clipboard.py', + 'templates/dynamiclauncher.py', + 'templates/email.py', + 'templates/filechooser.py', + 'templates/geoclue2.py', + 'templates/globalshortcuts.py', + 'templates/inhibit.py', + 'templates/__init__.py', + 'templates/inputcapture.py', + 'templates/lockdown.py', + 'templates/notification.py', + 'templates/print.py', + 'templates/remotedesktop.py', + 'templates/screenshot.py', + 'templates/settings.py', + 'templates/usb.py', + 'templates/wallpaper.py', +] + +foreach pytest_file : pytest_files + testname = pytest_file.replace('.py', '') + test( + 'pytest/@0@'.format(testname), + pytest, + args: [meson.current_source_dir()] + pytest_args + ['-k', testname], + env: pytest_env, + suite: ['pytest'], + timeout: 120, + ) +endforeach + +if enable_installed_tests + install_data( + pytest_files, + '__init__.py', + 'conftest.py', + 'asan.suppression', + install_dir: installed_tests_dir / 'tests', + ) + install_data( + template_files, + install_dir: installed_tests_dir / 'tests' / 'templates', + ) + + installed_env = { + 'XDG_DESKTOP_PORTAL_PATH': libexecdir / 'xdg-desktop-portal', + 'XDG_PERMISSION_STORE_PATH': libexecdir / 'xdg-permission-store', + 'XDG_DOCUMENT_PORTAL_PATH': libexecdir / 'xdg-document-portal', + 'XDP_VALIDATE_AUTO': '1', + } + env = '' + foreach key, value : installed_env + env += f'@key@=@value@ ' + endforeach foreach pytest_file : pytest_files testname = pytest_file.replace('.py', '') - test( - 'pytest/@0@'.format(testname), - pytest, - args: [meson.current_source_dir() / pytest_file] + pytest_args, - env: pytest_env, - suite: ['pytest'], - timeout: 120, - ) - endforeach - if enable_installed_tests - install_data( - pytest_files, - '__init__.py', - 'conftest.py', - 'asan.suppression', - install_dir: installed_tests_dir / 'tests', + exec = [pytest.full_path(), installed_tests_dir / 'tests' / pytest_file] + exec += pytest_args + exec += ['-p', 'no:cacheprovider'] + exec = ' '.join(exec) + + data = configuration_data() + data.set('exec', exec) + data.set('env', env) + data.set('libdir', libdir) + + configure_file( + input: 'template.test.in', + output: '@0@.test'.format(testname), + configuration: data, + install: true, + install_dir: installed_tests_data_dir, ) - install_data( - template_files, - install_dir: installed_tests_dir / 'tests' / 'templates', - ) - - installed_env = { - 'XDG_DESKTOP_PORTAL_PATH': libexecdir / 'xdg-desktop-portal', - 'XDG_PERMISSION_STORE_PATH': libexecdir / 'xdg-permission-store', - 'XDG_DOCUMENT_PORTAL_PATH': libexecdir / 'xdg-document-portal', - 'XDP_VALIDATE_AUTO': '1', - } - env = '' - foreach key, value : installed_env - env += f'@key@=@value@ ' - endforeach - - foreach pytest_file : pytest_files - testname = pytest_file.replace('.py', '') - - exec = [pytest.full_path(), installed_tests_dir / 'tests' / pytest_file] - exec += pytest_args - exec += ['-p', 'no:cacheprovider'] - exec = ' '.join(exec) - - data = configuration_data() - data.set('exec', exec) - data.set('env', env) - data.set('libdir', libdir) - - configure_file( - input: 'template.test.in', - output: '@0@.test'.format(testname), - configuration: data, - install: true, - install_dir: installed_tests_data_dir, - ) - endforeach - endif -endif + endforeach +endif \ No newline at end of file