aboutsummaryrefslogtreecommitdiff
path: root/run_unittests.py
diff options
context:
space:
mode:
Diffstat (limited to 'run_unittests.py')
-rwxr-xr-xrun_unittests.py85
1 files changed, 73 insertions, 12 deletions
diff --git a/run_unittests.py b/run_unittests.py
index 7326800..d1c192f 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -19,7 +19,7 @@ import re, json
import tempfile
from glob import glob
import mesonbuild.environment
-from mesonbuild.environment import detect_ninja
+from mesonbuild.environment import detect_ninja, Environment
from mesonbuild.dependencies import PkgConfigDependency
def get_soname(fname):
@@ -33,6 +33,12 @@ def get_soname(fname):
return m.group(1)
raise RuntimeError('Could not determine soname:\n\n' + raw_out)
+def get_fake_options():
+ import argparse
+ opts = argparse.Namespace()
+ opts.cross_file = None
+ return opts
+
class FakeEnvironment(object):
def __init__(self):
self.cross_info = None
@@ -81,11 +87,13 @@ class LinuxlikeTests(unittest.TestCase):
def _run(self, command):
self.output += subprocess.check_output(command, env=os.environ.copy())
- def init(self, srcdir):
+ def init(self, srcdir, extra_args=None):
+ if extra_args is None:
+ extra_args = []
args = [srcdir, self.builddir,
'--prefix', self.prefix,
'--libdir', self.libdir]
- self._run(self.meson_command + args)
+ self._run(self.meson_command + args + extra_args)
self.privatedir = os.path.join(self.builddir, 'meson-private')
def build(self):
@@ -170,7 +178,7 @@ class LinuxlikeTests(unittest.TestCase):
testdir = os.path.join(self.common_test_dir, '3 static')
self.init(testdir)
compdb = self.get_compdb()
- self.assertTrue('-fPIC' in compdb[0]['command'])
+ self.assertIn('-fPIC', compdb[0]['command'])
# This is needed to increase the difference between build.ninja's
# timestamp and coredata.dat's timestamp due to a Ninja bug.
# https://github.com/ninja-build/ninja/issues/371
@@ -179,7 +187,7 @@ class LinuxlikeTests(unittest.TestCase):
# Regenerate build
self.build()
compdb = self.get_compdb()
- self.assertTrue('-fPIC' not in compdb[0]['command'])
+ self.assertNotIn('-fPIC', compdb[0]['command'])
def test_pkgconfig_gen(self):
'''
@@ -196,7 +204,7 @@ class LinuxlikeTests(unittest.TestCase):
simple_dep = PkgConfigDependency('libfoo', env, kwargs)
self.assertTrue(simple_dep.found())
self.assertEqual(simple_dep.get_version(), '1.0')
- self.assertTrue('-lfoo' in simple_dep.get_link_args())
+ self.assertIn('-lfoo', simple_dep.get_link_args())
def test_vala_c_warnings(self):
'''
@@ -221,15 +229,15 @@ class LinuxlikeTests(unittest.TestCase):
self.assertIsNotNone(vala_command)
self.assertIsNotNone(c_command)
# -w suppresses all warnings, should be there in Vala but not in C
- self.assertTrue('-w' in vala_command)
- self.assertFalse('-w' in c_command)
+ self.assertIn("'-w'", vala_command)
+ self.assertNotIn("'-w'", c_command)
# -Wall enables all warnings, should be there in C but not in Vala
- self.assertFalse('-Wall' in vala_command)
- self.assertTrue('-Wall' in c_command)
+ self.assertNotIn("'-Wall'", vala_command)
+ self.assertIn("'-Wall'", c_command)
# -Werror converts warnings to errors, should always be there since it's
# injected by an unrelated piece of code and the project has werror=true
- self.assertTrue('-Werror' in vala_command)
- self.assertTrue('-Werror' in c_command)
+ self.assertIn("'-Werror'", vala_command)
+ self.assertIn("'-Werror'", c_command)
def test_static_compile_order(self):
'''
@@ -410,6 +418,59 @@ class LinuxlikeTests(unittest.TestCase):
self.assertTrue('TEST_ENV is set' in vg_log)
self.assertTrue('Memcheck' in vg_log)
+ def _test_stds_impl(self, testdir, compiler, p):
+ lang_std = p + '_std'
+ # Check that all the listed -std=xxx options for this compiler work
+ # just fine when used
+ for v in compiler.get_options()[lang_std].choices:
+ std_opt = '{}={}'.format(lang_std, v)
+ self.init(testdir, ['-D' + std_opt])
+ cmd = self.get_compdb()[0]['command']
+ if v != 'none':
+ cmd_std = "'-std={}'".format(v)
+ self.assertIn(cmd_std, cmd)
+ try:
+ self.build()
+ except:
+ print('{} was {!r}'.format(lang_std, v))
+ raise
+ self.wipe()
+ # Check that an invalid std option in CFLAGS/CPPFLAGS fails
+ # Needed because by default ICC ignores invalid options
+ cmd_std = '-std=FAIL'
+ env_flags = p.upper() + 'FLAGS'
+ os.environ[env_flags] = cmd_std
+ self.init(testdir)
+ cmd = self.get_compdb()[0]['command']
+ qcmd_std = "'{}'".format(cmd_std)
+ self.assertIn(qcmd_std, cmd)
+ with self.assertRaises(subprocess.CalledProcessError,
+ msg='{} should have failed'.format(qcmd_std)):
+ self.build()
+
+ def test_compiler_c_stds(self):
+ '''
+ Test that C stds specified for this compiler can all be used. Can't be
+ an ordinary test because it requires passing options to meson.
+ '''
+ testdir = os.path.join(self.common_test_dir, '1 trivial')
+ env = Environment(testdir, self.builddir, self.meson_command,
+ get_fake_options(), [])
+ cc = env.detect_c_compiler(False)
+ self._test_stds_impl(testdir, cc, 'c')
+
+ def test_compiler_cpp_stds(self):
+ '''
+ Test that C++ stds specified for this compiler can all be used. Can't
+ be an ordinary test because it requires passing options to meson.
+ '''
+ testdir = os.path.join(self.common_test_dir, '2 cpp')
+ env = Environment(testdir, self.builddir, self.meson_command,
+ get_fake_options(), [])
+ cpp = env.detect_cpp_compiler(False)
+ self._test_stds_impl(testdir, cpp, 'cpp')
+
+
class RewriterTests(unittest.TestCase):
def setUp(self):