From 108de85e21b5068bc5d9449bfe32e0aa3084f87c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20M=C3=A4rdian?= Date: Mon, 29 Jul 2024 11:58:05 +0900 Subject: [PATCH] meson: Add 'testing' option --- meson.build | 151 +++++++++++++++++++++++----------------------- meson_options.txt | 1 + src/meson.build | 20 +++--- 3 files changed, 88 insertions(+), 84 deletions(-) diff --git a/meson.build b/meson.build index b29174de4..908dd7752 100644 --- a/meson.build +++ b/meson.build @@ -23,10 +23,10 @@ systemd_generator_dir = systemd.get_variable(pkgconfig: 'systemdsystemgeneratord bash_completions_dir = completions.get_variable(pkgconfig: 'completionsdir', default_value: '/etc/bash_completion.d') # Order: Fedora/Mageia/openSUSE || Debian/Ubuntu -pyflakes = find_program('pyflakes-3', 'pyflakes3', required: false) -pycodestyle = find_program('pycodestyle-3', 'pycodestyle', 'pep8', required: false) -pytest = find_program('pytest-3', 'pytest3') # also requires the pytest-cov plugin -pycoverage = find_program('coverage-3', 'python3-coverage') +pyflakes = find_program('pyflakes-3', 'pyflakes3', required: get_option('testing')) +pycodestyle = find_program('pycodestyle-3', 'pycodestyle', 'pep8', required: get_option('testing')) +pytest = find_program('pytest-3', 'pytest3', required: get_option('testing')) # also requires the pytest-cov plugin +pycoverage = find_program('coverage-3', 'python3-coverage', required: get_option('testing')) pandoc = find_program('pandoc', required: false) find = find_program('find') @@ -70,77 +70,78 @@ test_env = [ 'G_DEBUG=fatal_criticals', ] -if get_option('unit_testing') - subdir('tests/ctests') -endif - -#FIXME: exclude doc/env/ -test('linting', - pyflakes, - timeout: 100, - args: [meson.current_source_dir()]) -test('codestyle', - pycodestyle, - timeout: 100, - args: ['--max-line-length=130', '--exclude=doc/env,*meson-private/pycompile.py', meson.current_source_dir()]) -test('documentation', - find_program('tests/validate_docs.sh'), - timeout: 100, - workdir: meson.current_source_dir()) -test('legacy-tests', - find_program('tests/cli_legacy.py'), - timeout: 900, - env: test_env) -#TODO: split out dbus tests into own test() instance, to run in parallel -test('unit-tests', - pycoverage, - args: ['run', '-a', '-m', 'pytest', '-s', '-v', '--cov-append', meson.current_source_dir()], - timeout: 600, - env: test_env) +if get_option('testing') + if get_option('unit_testing') + subdir('tests/ctests') + endif -#TODO: the coverage section should probably be cleaned up a bit -if get_option('b_coverage') - message('Find coverage reports in /meson-logs/coveragereport[-py]/') - # Using gcovr instead of lcov/gcov. - # The 'ninja coverage' command will produce the html/txt reports for C implicitly - #lcov = find_program('lcov') - #gcov = find_program('gcov') - #genhtml = find_program('genhtml') - gcovr = find_program('gcovr') - ninja = find_program('ninja') - grep = find_program('grep') - cat = find_program('cat') - test('coverage-c-output', - find_program('ninja'), - args: ['-C', meson.current_build_dir(), 'coverage'], - timeout: 60, - priority: -90, # run before 'coverage-c' - is_parallel: false) - test('coverage-c-cat', - cat, - args: [join_paths(meson.current_build_dir(), 'meson-logs', 'coverage.txt')], - priority: -98, # run before 'coverage-c' - is_parallel: false) - test('coverage-c', - grep, - args: ['^TOTAL.*100%$', join_paths(meson.current_build_dir(), 'meson-logs', 'coverage.txt')], - priority: -99, # run last - is_parallel: false) - test('coverage-py-combine', - pycoverage, - args: ['combine', '-a', meson.current_build_dir()], - priority: -90, # run before 'coverage-py-output' - is_parallel: false) - test('coverage-py-output', + #FIXME: exclude doc/env/ + test('linting', + pyflakes, + timeout: 100, + args: [meson.current_source_dir()]) + test('codestyle', + pycodestyle, + timeout: 100, + args: ['--max-line-length=130', '--exclude=doc/env,*meson-private/pycompile.py', meson.current_source_dir()]) + test('documentation', + find_program('tests/validate_docs.sh'), + timeout: 100, + workdir: meson.current_source_dir()) + test('legacy-tests', + find_program('tests/cli_legacy.py'), + timeout: 900, + env: test_env) + #TODO: split out dbus tests into own test() instance, to run in parallel + test('unit-tests', pycoverage, - args: ['html', '-d', join_paths(meson.current_build_dir(), - 'meson-logs', 'coveragereport-py'), '--omit=/usr/*'], - priority: -95, # run before 'coverage-py' - is_parallel: false) - test('coverage-py', - pycoverage, - args: ['report', '--omit=/usr/*', '--show-missing', '--fail-under=100'], - priority: -99, # run last - is_parallel: false) -endif + args: ['run', '-a', '-m', 'pytest', '-s', '-v', '--cov-append', meson.current_source_dir()], + timeout: 600, + env: test_env) + #TODO: the coverage section should probably be cleaned up a bit + if get_option('b_coverage') + message('Find coverage reports in /meson-logs/coveragereport[-py]/') + # Using gcovr instead of lcov/gcov. + # The 'ninja coverage' command will produce the html/txt reports for C implicitly + #lcov = find_program('lcov') + #gcov = find_program('gcov') + #genhtml = find_program('genhtml') + gcovr = find_program('gcovr') + ninja = find_program('ninja') + grep = find_program('grep') + cat = find_program('cat') + test('coverage-c-output', + find_program('ninja'), + args: ['-C', meson.current_build_dir(), 'coverage'], + timeout: 60, + priority: -90, # run before 'coverage-c' + is_parallel: false) + test('coverage-c-cat', + cat, + args: [join_paths(meson.current_build_dir(), 'meson-logs', 'coverage.txt')], + priority: -98, # run before 'coverage-c' + is_parallel: false) + test('coverage-c', + grep, + args: ['^TOTAL.*100%$', join_paths(meson.current_build_dir(), 'meson-logs', 'coverage.txt')], + priority: -99, # run last + is_parallel: false) + test('coverage-py-combine', + pycoverage, + args: ['combine', '-a', meson.current_build_dir()], + priority: -90, # run before 'coverage-py-output' + is_parallel: false) + test('coverage-py-output', + pycoverage, + args: ['html', '-d', join_paths(meson.current_build_dir(), + 'meson-logs', 'coveragereport-py'), '--omit=/usr/*'], + priority: -95, # run before 'coverage-py' + is_parallel: false) + test('coverage-py', + pycoverage, + args: ['report', '--omit=/usr/*', '--show-missing', '--fail-under=100'], + priority: -99, # run last + is_parallel: false) + endif +endif diff --git a/meson_options.txt b/meson_options.txt index 3dfc1c880..29b118746 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1 +1,2 @@ +option('testing', type: 'boolean', value: true) option('unit_testing', type: 'boolean', value: true) diff --git a/src/meson.build b/src/meson.build index 8e5face51..c7e631100 100644 --- a/src/meson.build +++ b/src/meson.build @@ -21,15 +21,17 @@ libnetplan = library( soversion: 1, install: true) -libnetplan_testing = library( - 'netplan_testing', - sources, - gnu_symbol_visibility: 'default', - c_args: ['-DUNITTESTS'], - dependencies: [glib, gio, yaml, uuid], - include_directories: inc, - soversion: 1, - install: false) +if get_option('testing') + libnetplan_testing = library( + 'netplan_testing', + sources, + gnu_symbol_visibility: 'default', + c_args: ['-DUNITTESTS'], + dependencies: [glib, gio, yaml, uuid], + include_directories: inc, + soversion: 1, + install: false) +endif libexec_netplan = join_paths(get_option('libexecdir'), 'netplan') executable(