[nautilus/meson-test-env: 4/4] build: Set a couple env vars when running tests



commit cfa26f0cfe827e84d4ae0501e80fa65b190ff0ee
Author: Ernestas Kulik <ernestask gnome org>
Date:   Thu May 17 13:28:13 2018 +0300

    build: Set a couple env vars when running tests
    
    This will save some time/thinking when running tests manually.
    G_TEST_BUILDDIR and G_TEST_SRCDIR will be useful if
    g_test_build_filename() is ever used, since our primary build mode is
    outside the source directory, which would break the function.

 test/automated/display/meson.build     | 15 ++++++++++++++-
 test/automated/displayless/meson.build | 10 +++++++++-
 test/meson.build                       | 19 +++++++++++++++++++
 3 files changed, 42 insertions(+), 2 deletions(-)
---
diff --git a/test/automated/display/meson.build b/test/automated/display/meson.build
index 1edd7b60d..171730e43 100644
--- a/test/automated/display/meson.build
+++ b/test/automated/display/meson.build
@@ -1,3 +1,8 @@
+test_env += [
+  'G_TEST_BUILDDIR=@0@'.format(meson.current_build_dir()),
+  'G_TEST_SRCDIR=@0@'.format(meson.current_source_dir())
+]
+
 tests = [
   ['test-nautilus-search-engine', [
     'test-nautilus-search-engine.c'
@@ -8,5 +13,13 @@ tests = [
 ]
 
 foreach t: tests
-  test(t[0], executable(t[0], t[1], dependencies: libnautilus_dep))
+  test(
+    t[0],
+    executable(t[0], t[1], dependencies: libnautilus_dep),
+    env: [
+      test_env,
+      'G_TEST_BUILDDIR=@0@'.format(meson.current_build_dir()),
+      'G_TEST_SRCDIR=@0@'.format(meson.current_source_dir())
+    ]
+  )
 endforeach
diff --git a/test/automated/displayless/meson.build b/test/automated/displayless/meson.build
index cd7573417..0c3a3e13d 100644
--- a/test/automated/displayless/meson.build
+++ b/test/automated/displayless/meson.build
@@ -11,5 +11,13 @@ tests = [
 ]
 
 foreach t: tests
-  test(t[0], executable(t[0], t[1], dependencies: libnautilus_dep))
+  test(
+    t[0],
+    executable(t[0], t[1], dependencies: libnautilus_dep),
+    env: [
+      test_env,
+      'G_TEST_BUILDDIR=@0@'.format(meson.current_build_dir()),
+      'G_TEST_SRCDIR=@0@'.format(meson.current_source_dir())
+    ]
+  )
 endforeach
diff --git a/test/meson.build b/test/meson.build
index 6fd5e6005..815705509 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -1,2 +1,21 @@
+# When adding new tests, it is useful to set some environment variables.
+# You can do it like so:
+#
+# test(
+#   name,
+#   executable,
+#   env: [
+#     test_env,
+#     'G_TEST_BUILDDIR=@0@'.format(meson.current_build_dir()),
+#     'G_TEST_SRCDIR=@0@'.format(meson.current_source_dir())
+#   ]
+# )
+#
+# G_TEST_BUILDDIR and G_TEST_SRCDIR cannot be preset, since
+# the test sources are scattered.
+test_env = [
+  'GSETTINGS_SCHEMA_DIR=@0@'.format(join_paths(meson.build_root(), 'data'))
+]
+
 subdir('automated')
 subdir('interactive')


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