Can set envvars in test setups.

pull/1254/head
Jussi Pakkanen 8 years ago
parent ee8a6e6fc5
commit 74f15263b6
  1. 5
      mesonbuild/interpreter.py
  2. 8
      mesontest.py
  3. 13
      run_unittests.py
  4. 3
      test cases/unit/2 testsetups/buggy.c
  5. 1
      test cases/unit/2 testsetups/meson.build

@ -30,6 +30,7 @@ from .interpreterbase import InterpreterException, InvalidArguments, InvalidCode
from .interpreterbase import InterpreterObject, MutableInterpreterObject
import os, sys, shutil, uuid
import re
import importlib
@ -1207,7 +1208,7 @@ class Interpreter(InterpreterBase):
'add_project_arguments': self.func_add_project_arguments,
'add_global_link_arguments': self.func_add_global_link_arguments,
'add_project_link_arguments': self.func_add_project_link_arguments,
'add_test_setup' : self.func_add_test_setup,
'add_test_setup': self.func_add_test_setup,
'add_languages': self.func_add_languages,
'find_program': self.func_find_program,
'find_library': self.func_find_library,
@ -2146,6 +2147,8 @@ requirements use the version keyword argument instead.''')
if len(args) != 1:
raise InterpreterException('Add_test_setup needs one argument for the setup name.')
setup_name = args[0]
if re.fullmatch('[_a-zA-Z][_0-9a-zA-Z]*', setup_name) is None:
raise InterpreterException('Setup name may only contain alphanumeric characters.')
try:
exe_wrapper = mesonlib.stringlistify(kwargs['exe_wrapper'])
except KeyError:

@ -208,6 +208,7 @@ class TestHarness:
cmd = wrap + cmd + test.cmd_args
starttime = time.time()
child_env = os.environ.copy()
child_env.update(self.options.global_env.get_env(child_env))
if isinstance(test.env, build.EnvironmentVariables):
test.env = test.env.get_env(child_env)
@ -477,6 +478,7 @@ def merge_suite_options(options):
sys.exit('Conflict: both test setup and command line specify an exe wrapper.')
if options.wrapper is None:
options.wrapper = current.exe_wrapper
return current.env
def run(args):
options = parser.parse_args(args)
@ -484,7 +486,11 @@ def run(args):
options.num_processes = 1
if options.setup is not None:
merge_suite_options(options)
global_env = merge_suite_options(options)
else:
global_env = build.EnvironmentVariables()
setattr(options, 'global_env', global_env)
if options.gdb:
options.verbose = True

@ -57,6 +57,7 @@ class LinuxlikeTests(unittest.TestCase):
src_root = os.path.dirname(__file__)
src_root = os.path.join(os.getcwd(), src_root)
self.builddir = tempfile.mkdtemp()
self.logdir = os.path.join(self.builddir, 'meson-logs')
self.prefix = '/usr'
self.libdir = os.path.join(self.prefix, 'lib')
self.installdir = os.path.join(self.builddir, 'install')
@ -392,12 +393,22 @@ class LinuxlikeTests(unittest.TestCase):
self.assertListEqual(meson_exe_dat1, meson_exe_dat2)
def test_testsetups(self):
if not shutil.which('valgrind'):
raise unittest.SkipTest('Valgrind not installed.')
testdir = os.path.join(self.unit_test_dir, '2 testsetups')
self.init(testdir)
self.build()
self.run_tests()
with open(os.path.join(self.logdir, 'testlog.txt')) as f:
basic_log = f.read()
self.assertRaises(subprocess.CalledProcessError,
self._run, self.mtest_command + ['--setup=valgrind'])
self._run, self.mtest_command + ['--setup=valgrind'])
with open(os.path.join(self.logdir, 'testlog-valgrind.txt')) as f:
vg_log = f.read()
self.assertFalse('TEST_ENV is set' in basic_log)
self.assertFalse('Memcheck' in basic_log)
self.assertTrue('TEST_ENV is set' in vg_log)
self.assertTrue('Memcheck' in vg_log)
class RewriterTests(unittest.TestCase):

@ -7,5 +7,8 @@ int main(int argc, char **argv) {
char *ten = malloc(10);
do_nasty(ten);
free(ten);
if(getenv("TEST_ENV")) {
printf("TEST_ENV is set.\n");
}
return 0;
}

@ -2,6 +2,7 @@ project('testsetups', 'c')
vg = find_program('valgrind', required : false)
# This is only set when running under Valgrind test setup.
env = environment()
env.set('TEST_ENV', '1')

Loading…
Cancel
Save