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.
This commit is contained in:
Iain Lane 2019-02-12 11:29:10 +00:00
parent f773b3533a
commit 07a1a8031d
No known key found for this signature in database
GPG Key ID: E352D5C51C5041D4
8 changed files with 19 additions and 1 deletions

View File

@ -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',

View File

@ -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',

View File

@ -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',

View File

@ -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)

View File

@ -1,4 +1,4 @@
[Test]
Type=session
Exec=@installed_tests_dir@/@program@ --tap
Exec=@env@@installed_tests_dir@/@program@ --tap
Output=TAP

View File

@ -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',

View File

@ -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',

View File

@ -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',