Skip to content

Commit

Permalink
meson: Add 'testing' option
Browse files Browse the repository at this point in the history
  • Loading branch information
slyon authored and daniloegea committed Jul 30, 2024
1 parent 666b2da commit 108de85
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 84 deletions.
151 changes: 76 additions & 75 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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 <BUILDDIR>/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 <BUILDDIR>/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
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
option('testing', type: 'boolean', value: true)
option('unit_testing', type: 'boolean', value: true)
20 changes: 11 additions & 9 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 108de85

Please sign in to comment.