Can specify a working directory for tests. Closes #326.

pull/329/head
Jussi Pakkanen 9 years ago
parent d5bdfb5906
commit 23c6de3461
  1. 5
      backends.py
  2. 13
      interpreter.py
  3. 2
      meson_test.py
  4. 6
      test cases/common/100 test workdir/meson.build
  5. 12
      test cases/common/100 test workdir/opener.c
  6. 4
      test cases/failing/23 rel testdir/meson.build
  7. 3
      test cases/failing/23 rel testdir/simple.c

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

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

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

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

@ -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;
}

@ -0,0 +1,4 @@
project('nonabs workdir', 'c')
exe = executable('simple', 'simple.c')
test('simple', exe, workdir : '.')

@ -0,0 +1,3 @@
int main(int argc, char **argv) {
return 0;
}
Loading…
Cancel
Save