build: Modernize and deduplicate setting up test targets

Get rid of the duplication by rolling (almost) every test into a loop.
We now iterate over an array containing at least the name and list of sources.
To account for some differences between individual tests, we allow an
optional third array consisting of a dictionary for extra arguments.

In particular we ensure that the `test()` target now always depends on
the test binary, so that it will get properly rebuilt on changes to
the sources.

Note, that we're resorting in a separate commit, to ease reviewing.

Signed-off-by: Evangelos Ribeiro Tzaras <devrtz@fortysixandtwo.eu>
Part-of: <https://gitlab.gnome.org/GNOME/calls/-/merge_requests/798>
This commit is contained in:
Evangelos Ribeiro Tzaras
2025-10-14 11:01:20 +02:00
committed by Marge Bot
parent fec9e953ae
commit 93a5c1911d

View File

@@ -46,140 +46,55 @@ test_includes = include_directories('.')
subdir('mock') subdir('mock')
subdir('services') subdir('services')
test_sources = ['test-emergency-call-types.c'] tests = [
t = executable( ['emergency-call-types', ['test-emergency-call-types.c']],
'emergency-call-types', ['manager', ['test-manager.c'], {'extra_test_deps' : [calls_plugins]}],
test_sources, [
c_args: test_cflags,
link_args: test_link_args,
pie: true,
link_with: [calls_vala, libcalls],
dependencies: calls_deps,
include_directories: [calls_includes],
)
test('emergency-call-types', t, env: test_env)
test_sources = ['test-service-providers.c']
t = executable(
'service-providers',
test_sources,
c_args: test_cflags,
link_args: test_link_args,
pie: true,
link_with: [calls_vala, libcalls],
dependencies: calls_deps,
include_directories: [calls_includes],
)
test('service-providers', t, env: test_env)
test_sources = ['test-manager.c']
t = executable(
'manager',
test_sources,
c_args: test_cflags,
link_args: test_link_args,
pie: true,
link_with: [calls_vala, libcalls],
dependencies: calls_deps,
include_directories: [calls_includes],
)
test('manager', t, env: test_env, depends: calls_plugins)
test_sources = ['test-plugins.c']
t = executable(
'plugins', 'plugins',
test_sources, ['test-plugins.c', calls_sources],
calls_sources, {'extra_test_deps' : [calls_plugins]},
c_args: test_cflags, ],
link_args: test_link_args, ['util', ['test-util.c']],
pie: true, ['ui-call', ['test-ui-call.c', 'mock-call.c']],
link_with: [calls_vala, libcalls], ['contacts', ['test-contacts.c']],
dependencies: calls_deps, ['settings', ['test-settings.c']],
include_directories: [calls_includes], ['dbus', ['test-dbus.c', generated_dbus_sources]],
) [
test('plugins', t, env: test_env, depends: calls_plugins)
test_sources = ['test-util.c']
t = executable(
'util',
test_sources,
c_args: test_cflags,
link_args: test_link_args,
pie: true,
link_with: [calls_vala, libcalls],
dependencies: calls_deps,
include_directories: [calls_includes],
)
test('util', t, env: test_env)
test_sources = ['test-ui-call.c', 'mock-call.c', 'mock-call.h']
t = executable(
'ui-call',
test_sources,
c_args: test_cflags,
link_args: test_link_args,
pie: true,
link_with: [calls_vala, libcalls],
dependencies: calls_deps,
include_directories: [calls_includes],
)
test('ui-call', t, env: test_env)
test_sources = ['mock-call.c', 'mock-call.h', 'test-ringer.c']
t = executable(
'ringer', 'ringer',
test_sources, ['mock-call.c', 'test-ringer.c'],
c_args: test_cflags, {'extra_link_with' : libfeedback},
link_args: test_link_args, ],
pie: true, ['service-providers', ['test-service-providers.c']],
link_with: [calls_vala, libcalls, libfeedback], ]
dependencies: calls_deps,
include_directories: [calls_includes],
)
test('ringer', t, env: test_env)
test_sources = ['test-contacts.c'] foreach t : tests
t = executable( test_name = t[0]
'contacts', test_sources = t[1]
test_sources, link_with = [calls_vala, libcalls]
c_args: test_cflags,
link_args: test_link_args,
pie: true,
link_with: [calls_vala, libcalls],
dependencies: calls_deps,
include_directories: [calls_includes],
)
test('contacts', t, env: test_env)
test_sources = ['test-settings.c'] if t.length() == 3 and t[2].has_key('extra_link_with')
t = executable( link_with += t[2]['extra_link_with']
'settings', endif
test_sources,
c_args: test_cflags,
link_args: test_link_args,
pie: true,
link_with: [calls_vala, libcalls],
dependencies: calls_deps,
include_directories: [calls_includes],
)
test('settings', t, env: test_env)
test_sources = ['test-dbus.c'] exe = executable(
t = executable( test_name,
'dbus',
test_sources, test_sources,
generated_dbus_sources,
c_args: test_cflags, c_args: test_cflags,
link_args: test_link_args, link_args: test_link_args,
pie: true, pie: true,
link_with: [calls_vala, libcalls], link_with: link_with,
dependencies: calls_deps, dependencies: calls_deps,
include_directories: [calls_includes], include_directories: [calls_includes, test_includes],
) )
test('dbus', t, env: test_env)
test_deps = [exe]
if t.length() == 3 and t[2].has_key('extra_test_deps')
test_deps += t[2]['extra_test_deps']
endif
test(t[0], exe, env: test_env, depends: test_deps)
endforeach
dbus_run_session = find_program('dbus-run-session') dbus_run_session = find_program('dbus-run-session')