diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2015-12-08 15:45:51 +0200 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2015-12-08 15:45:51 +0200 |
commit | 23c6de34610080ba38e44b04622486f918e53809 (patch) | |
tree | 529432c3f4e1f0b9c7f903312ada1dfe4d2678b6 | |
parent | d5bdfb5906563f031c17cfa9564a03ed475053b9 (diff) | |
download | meson-23c6de34610080ba38e44b04622486f918e53809.zip meson-23c6de34610080ba38e44b04622486f918e53809.tar.gz meson-23c6de34610080ba38e44b04622486f918e53809.tar.bz2 |
Can specify a working directory for tests. Closes #326.
-rw-r--r-- | backends.py | 5 | ||||
-rw-r--r-- | interpreter.py | 13 | ||||
-rwxr-xr-x | meson_test.py | 2 | ||||
-rw-r--r-- | test cases/common/100 test workdir/meson.build | 6 | ||||
-rw-r--r-- | test cases/common/100 test workdir/opener.c | 12 | ||||
-rw-r--r-- | test cases/failing/23 rel testdir/meson.build | 4 | ||||
-rw-r--r-- | test cases/failing/23 rel testdir/simple.c | 3 |
7 files changed, 40 insertions, 5 deletions
diff --git a/backends.py b/backends.py index 03ecd4b..7f7c338 100644 --- a/backends.py +++ b/backends.py @@ -21,7 +21,7 @@ from coredata import MesonException class TestSerialisation: def __init__(self, name, fname, is_cross, exe_wrapper, is_parallel, cmd_args, env, - should_fail, valgrind_args, timeout, extra_paths): + should_fail, valgrind_args, timeout, workdir, extra_paths): self.name = name self.fname = fname self.is_cross = is_cross @@ -32,6 +32,7 @@ class TestSerialisation: self.should_fail = should_fail self.valgrind_args = valgrind_args self.timeout = timeout + self.workdir = workdir self.extra_paths = extra_paths # This class contains the basic functionality that is needed by all backends. @@ -303,7 +304,7 @@ class Backend(): cmd_args.append(a) ts = TestSerialisation(t.get_name(), fname, is_cross, exe_wrapper, t.is_parallel, cmd_args, t.env, t.should_fail, t.valgrind_args, - t.timeout, extra_paths) + t.timeout, t.workdir, extra_paths) arr.append(ts) pickle.dump(arr, datafile) diff --git a/interpreter.py b/interpreter.py index f4c09a4..e7f7a3a 100644 --- a/interpreter.py +++ b/interpreter.py @@ -528,7 +528,7 @@ class RunTargetHolder(InterpreterObject): self.held_object = build.RunTarget(name, command, args, subdir) class Test(InterpreterObject): - def __init__(self, name, exe, is_parallel, cmd_args, env, should_fail, valgrind_args, timeout): + def __init__(self, name, exe, is_parallel, cmd_args, env, should_fail, valgrind_args, timeout, workdir): InterpreterObject.__init__(self) self.name = name self.exe = exe @@ -538,6 +538,7 @@ class Test(InterpreterObject): self.should_fail = should_fail self.valgrind_args = valgrind_args self.timeout = timeout + self.workdir = workdir def get_exe(self): return self.exe @@ -1723,9 +1724,17 @@ class Interpreter(): if not isinstance(should_fail, bool): raise InterpreterException('Keyword argument should_fail must be a boolean.') timeout = kwargs.get('timeout', 30) + if 'workdir' in kwargs: + workdir = kwargs['workdir'] + if not isinstance(workdir, str): + raise InterpreterException('Workdir keyword argument must be a string.') + if not os.path.isabs(workdir): + raise InterpreterException('Workdir keyword argument must be an absolute path.') + else: + workdir = None if not isinstance(timeout, int): raise InterpreterException('Timeout must be an integer.') - t = Test(args[0], args[1].held_object, par, cmd_args, env, should_fail, valgrind_args, timeout) + t = Test(args[0], args[1].held_object, par, cmd_args, env, should_fail, valgrind_args, timeout, workdir) if is_base_test: self.build.tests.append(t) mlog.debug('Adding test "', mlog.bold(args[0]), '".', sep='') diff --git a/meson_test.py b/meson_test.py index 8061215..a7ba7de 100755 --- a/meson_test.py +++ b/meson_test.py @@ -104,7 +104,7 @@ def run_single_test(wrap, test): if len(test.extra_paths) > 0: child_env['PATH'] = child_env['PATH'] + ';'.join([''] + test.extra_paths) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - env=child_env) + env=child_env, cwd=test.workdir) timed_out = False try: (stdo, stde) = p.communicate(timeout=test.timeout) diff --git a/test cases/common/100 test workdir/meson.build b/test cases/common/100 test workdir/meson.build new file mode 100644 index 0000000..1323a17 --- /dev/null +++ b/test cases/common/100 test workdir/meson.build @@ -0,0 +1,6 @@ +project('test workdir', 'c') + +exe = executable('opener', 'opener.c') + +test('basic', exe, workdir : meson.source_root()) +test('shouldfail', exe, should_fail : true) diff --git a/test cases/common/100 test workdir/opener.c b/test cases/common/100 test workdir/opener.c new file mode 100644 index 0000000..43c53ce --- /dev/null +++ b/test cases/common/100 test workdir/opener.c @@ -0,0 +1,12 @@ +// This test only succeeds if run in the source root dir. + +#include<stdio.h> + +int main(int arg, char **argv) { + FILE *f = fopen("opener.c", "r"); + if(f) { + fclose(f); + return 0; + } + return 1; +} diff --git a/test cases/failing/23 rel testdir/meson.build b/test cases/failing/23 rel testdir/meson.build new file mode 100644 index 0000000..c10558b --- /dev/null +++ b/test cases/failing/23 rel testdir/meson.build @@ -0,0 +1,4 @@ +project('nonabs workdir', 'c') + +exe = executable('simple', 'simple.c') +test('simple', exe, workdir : '.') diff --git a/test cases/failing/23 rel testdir/simple.c b/test cases/failing/23 rel testdir/simple.c new file mode 100644 index 0000000..11b7fad --- /dev/null +++ b/test cases/failing/23 rel testdir/simple.c @@ -0,0 +1,3 @@ +int main(int argc, char **argv) { + return 0; +} |