[glib: 1/3] installed tests: Allow tests to set environment variables



commit 07a1a8031d7bc63e8bd5d524969a1efb14cd830a
Author: Iain Lane <iainl gnome org>
Date:   Tue Feb 12 11:29:10 2019 +0000

    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.

 gio/tests/meson.build      | 10 ++++++++++
 glib/tests/meson.build     |  1 +
 gobject/tests/meson.build  |  1 +
 meson.build                |  3 +++
 template-tap.test.in       |  2 +-
 tests/gobject/meson.build  |  1 +
 tests/meson.build          |  1 +
 tests/refcount/meson.build |  1 +
 8 files changed, 19 insertions(+), 1 deletion(-)
---
diff --git a/gio/tests/meson.build b/gio/tests/meson.build
index e4b4959cb..843bc6da8 100644
--- a/gio/tests/meson.build
+++ b/gio/tests/meson.build
@@ -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',
diff --git a/glib/tests/meson.build b/glib/tests/meson.build
index 814ddbe01..d54fc41fa 100644
--- a/glib/tests/meson.build
+++ b/glib/tests/meson.build
@@ -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',
diff --git a/gobject/tests/meson.build b/gobject/tests/meson.build
index 44d4588d1..b7fb2364c 100644
--- a/gobject/tests/meson.build
+++ b/gobject/tests/meson.build
@@ -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',
diff --git a/meson.build b/meson.build
index 98907ca16..ad8c4cdd8 100644
--- a/meson.build
+++ b/meson.build
@@ -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)
diff --git a/template-tap.test.in b/template-tap.test.in
index 6adf73f03..30cd16686 100644
--- a/template-tap.test.in
+++ b/template-tap.test.in
@@ -1,4 +1,4 @@
 [Test]
 Type=session
-Exec=@installed_tests_dir@/@program@ --tap
+Exec=@env@@installed_tests_dir@/@program@ --tap
 Output=TAP
diff --git a/tests/gobject/meson.build b/tests/gobject/meson.build
index 4b1c69085..eabaea5b2 100644
--- a/tests/gobject/meson.build
+++ b/tests/gobject/meson.build
@@ -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',
diff --git a/tests/meson.build b/tests/meson.build
index 1d53db288..11075dd8e 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -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',
diff --git a/tests/refcount/meson.build b/tests/refcount/meson.build
index 22b9655d7..e17e38b45 100644
--- a/tests/refcount/meson.build
+++ b/tests/refcount/meson.build
@@ -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',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]