Verified Commit 07a1a803 authored by Iain Lane's avatar Iain Lane

installed tests: Allow tests to set environment variables

It's necessary sometimes for installed tests to be able to run with a
custom environment. For example, the gsocketclient-slow test requires an
LD_PRELOADed library to provide a slow connect() (this is to be added in
a followup commit).

Introduce a variable `@env@` into the installed test template, which we
can override as necessary when generating `.test` files, to run tests
prefixed with `/usr/bin/env <LIST OF VARIABLES>`.

As the only test that requires this currently lives in `gio/tests/`, we
are only hooking this up for that directory right now. If other tests in
future require this treatment, then the support can be extended at that
point.
parent f773b353
......@@ -593,11 +593,21 @@ foreach test_name, extra_args : gio_tests
source = extra_args.get('source', test_name + '.c')
extra_sources = extra_args.get('extra_sources', [])
install = installed_tests_enabled and extra_args.get('install', true)
installed_tests_env = extra_args.get('installed_tests_env', {})
if install
test_conf = configuration_data()
test_conf.set('installed_tests_dir', installed_tests_execdir)
test_conf.set('program', test_name)
test_env_override = ''
if installed_tests_env != {}
envs = []
foreach var, value : installed_tests_env
envs += '@0@=@1@'.format(var, value)
endforeach
test_env_override = '@0@ @1@ '.format(env_program.path(), ' '.join(envs))
endif
test_conf.set('env', test_env_override)
configure_file(
input: installed_tests_template_tap,
output: test_name + '.test',
......
......@@ -183,6 +183,7 @@ foreach test_name, extra_args : glib_tests
test_conf = configuration_data()
test_conf.set('installed_tests_dir', installed_tests_execdir)
test_conf.set('program', test_name)
test_conf.set('env', '')
configure_file(
input: installed_tests_template_tap,
output: test_name + '.test',
......
......@@ -77,6 +77,7 @@ foreach test_name, extra_args : gobject_tests
test_conf = configuration_data()
test_conf.set('installed_tests_dir', installed_tests_execdir)
test_conf.set('program', test_name)
test_conf.set('env', '')
configure_file(
input: installed_tests_template_tap,
output: test_name + '.test',
......
......@@ -1893,6 +1893,9 @@ endif
have_bash = find_program('bash', required : false).found() # For completion scripts
have_sh = find_program('sh', required : false).found() # For glib-gettextize
# Some installed tests require a custom environment
env_program = find_program('env', required: installed_tests_enabled)
# FIXME: How to detect Solaris? https://github.com/mesonbuild/meson/issues/1578
if host_system == 'sunos'
glib_conf.set('_XOPEN_SOURCE_EXTENDED', 1)
......
[Test]
Type=session
Exec=@installed_tests_dir@/@program@ --tap
Exec=@env@@installed_tests_dir@/@program@ --tap
Output=TAP
......@@ -66,6 +66,7 @@ foreach test_name, extra_args : gobject_tests
test_conf = configuration_data()
test_conf.set('installed_tests_dir', installed_tests_execdir)
test_conf.set('program', test_name)
test_conf.set('env', '')
configure_file(
input: template,
output: test_name + '.test',
......
......@@ -109,6 +109,7 @@ foreach test_name, extra_args : tests
test_conf = configuration_data()
test_conf.set('installed_tests_dir', installed_tests_execdir)
test_conf.set('program', test_name)
test_conf.set('env', '')
configure_file(
input: template,
output: test_name + '.test',
......
......@@ -36,6 +36,7 @@ foreach test_name, extra_args : refcount_tests
test_conf = configuration_data()
test_conf.set('installed_tests_dir', installed_tests_execdir)
test_conf.set('program', test_name)
test_conf.set('env', '')
configure_file(
input: installed_tests_template,
output: test_name + '.test',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment