summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Griffis <tingping@tingping.se>2017-06-21 13:48:43 -0400
committerPatrick Griffis <tingping@tingping.se>2017-06-21 16:06:30 -0400
commitbe74131344fdaa849b910190a8877955e5d89f96 (patch)
treead65a957d776e013ec072477c2cae5ce772971e7
parent624709bfc10b8bbdddd70fe814b00313facdc789 (diff)
downloadmeson-tingping/test-profile.tar.gz
Add profile kwarg to test()tingping/test-profile
-rw-r--r--docs/markdown/Reference-manual.md6
-rw-r--r--mesonbuild/backend/backends.py5
-rw-r--r--mesonbuild/interpreter.py23
-rw-r--r--test cases/common/154 test profiles/file.in0
-rw-r--r--test cases/common/154 test profiles/meson.build16
-rw-r--r--test cases/common/154 test profiles/test.c23
6 files changed, 69 insertions, 4 deletions
diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md
index 492666b96..2bcadf039 100644
--- a/docs/markdown/Reference-manual.md
+++ b/docs/markdown/Reference-manual.md
@@ -644,6 +644,12 @@ Defines an unit test. Takes two positional arguments, the first is the name of t
- `should_fail` when true the test is considered passed if the executable returns a non-zero return value (i.e. reports an error)
- `timeout` the amount of seconds the test is allowed to run, a test that exceeds its time limit is always considered failed, defaults to 30 seconds
- `workdir` absolute path that will be used as the working directory for the test
+- `profile` changes behavior in various ways to integrate with existing test suites, see below for details
+
+Supported profiles:
+
+- `glib`
+ Sets `G_TEST_SRCDIR` and `G_TEST_BUILDDIR` to integrate with [GLib's testing framwork](https://developer.gnome.org/glib/stable/glib-Testing.html)
Defined tests can be run in a backend-agnostic way by calling `mesontest` inside the build dir, or by using backend-specific commands, such as `ninja test` or `msbuild RUN_TESTS.vcxproj`.
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
index 1dd128b48..3637e2edd 100644
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -65,7 +65,7 @@ class ExecutableSerialisation:
class TestSerialisation:
def __init__(self, name, suite, fname, is_cross, exe_wrapper, is_parallel, cmd_args, env,
- should_fail, timeout, workdir, extra_paths):
+ should_fail, timeout, workdir, profile, extra_paths):
self.name = name
self.suite = suite
self.fname = fname
@@ -78,6 +78,7 @@ class TestSerialisation:
self.timeout = timeout
self.workdir = workdir
self.extra_paths = extra_paths
+ self.profile = profile
class OptionProxy:
def __init__(self, name, value):
@@ -526,7 +527,7 @@ class Backend:
raise MesonException('Bad object in test command.')
ts = TestSerialisation(t.get_name(), t.suite, cmd, is_cross, exe_wrapper,
t.is_parallel, cmd_args, t.env, t.should_fail,
- t.timeout, t.workdir, extra_paths)
+ t.timeout, t.workdir, t.profile, extra_paths)
arr.append(ts)
pickle.dump(arr, datafile)
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 7f279c1ee..c9a430946 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -582,7 +582,7 @@ class RunTargetHolder(InterpreterObject):
return r.format(self.__class__.__name__, h.get_id(), h.command)
class Test(InterpreterObject):
- def __init__(self, name, suite, exe, is_parallel, cmd_args, env, should_fail, timeout, workdir):
+ def __init__(self, name, suite, exe, is_parallel, cmd_args, env, should_fail, timeout, workdir, profile):
InterpreterObject.__init__(self)
self.name = name
self.suite = suite
@@ -593,6 +593,7 @@ class Test(InterpreterObject):
self.should_fail = should_fail
self.timeout = timeout
self.workdir = workdir
+ self.profile = profile
def get_exe(self):
return self.exe
@@ -2203,7 +2204,25 @@ class Interpreter(InterpreterBase):
suite.append(self.subproject.replace(' ', '_').replace(':', '_') + s)
else:
suite.append(self.build.project_name.replace(' ', '_').replace(':', '_') + s)
- t = Test(args[0], suite, args[1].held_object, par, cmd_args, env, should_fail, timeout, workdir)
+ profile = kwargs.get('profile')
+ if profile:
+ if not isinstance(profile, str):
+ raise InterpreterException('Test profile must be a string')
+ VALID_PROFILES = ('glib',)
+ if profile not in VALID_PROFILES:
+ raise InterpreterException('{} is not a valid test profile {}'.format(profile, VALID_PROFILES))
+ env.set(None, 'G_TEST_SRCDIR', self.environment.get_source_dir(), {})
+
+ if profile == 'glib':
+ if isinstance(env, dict):
+ env['G_TEST_SRCDIR'] = self.environment.get_source_dir()
+ env['G_TEST_BUILDDIR'] = self.environment.get_build_dir()
+ else:
+ # FIXME ...
+ env.set(None, 'G_TEST_SRCDIR', self.environment.get_source_dir(), {})
+ env.set(None, 'G_TEST_BUILDDIR', self.environment.get_build_dir(), {})
+
+ t = Test(args[0], suite, args[1].held_object, par, cmd_args, env, should_fail, timeout, workdir, profile)
if is_base_test:
self.build.tests.append(t)
mlog.debug('Adding test "', mlog.bold(args[0]), '".', sep='')
diff --git a/test cases/common/154 test profiles/file.in b/test cases/common/154 test profiles/file.in
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/test cases/common/154 test profiles/file.in
diff --git a/test cases/common/154 test profiles/meson.build b/test cases/common/154 test profiles/meson.build
new file mode 100644
index 000000000..5decd8beb
--- /dev/null
+++ b/test cases/common/154 test profiles/meson.build
@@ -0,0 +1,16 @@
+project('test project', 'c',
+ version: '1'
+)
+
+configure_file(
+ input: 'file.in',
+ output: 'file.out',
+ configuration: configuration_data()
+)
+
+test = executable('test-exe', 'test.c',
+ dependencies: dependency('glib-2.0')
+)
+
+test('Test GLib (with env dict)', test, profile: 'glib', env: 'foo=bar')
+test('Test GLib (with env object)', test, profile: 'glib', env: environment()) \ No newline at end of file
diff --git a/test cases/common/154 test profiles/test.c b/test cases/common/154 test profiles/test.c
new file mode 100644
index 000000000..72704c0ce
--- /dev/null
+++ b/test cases/common/154 test profiles/test.c
@@ -0,0 +1,23 @@
+#include <glib.h>
+
+static void test_source (void)
+{
+ const char *in_file = g_test_get_filename (G_TEST_DIST, "file.in", NULL);
+ g_assert_true (g_file_test (in_file, G_FILE_TEST_EXISTS));
+}
+
+static void test_build (void)
+{
+ const char *out_file = g_test_get_filename (G_TEST_BUILT, "file.out", NULL);
+ g_assert_true (g_file_test (out_file, G_FILE_TEST_EXISTS));
+}
+
+int main(int argc, char **argv)
+{
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/test_srcdir", test_source);
+ g_test_add_func ("/test_builddir", test_build);
+
+ return g_test_run ();
+}