aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2020-11-13 16:28:21 -0800
committerDylan Baker <dylan@pnwbakers.com>2020-11-16 10:19:15 -0800
commit3e89c30bae2265e694212a5909a553de0484dc14 (patch)
tree76cdbc29ae5b83cd6b675bf40c3b818cf863c537
parent85550e8fce3d2a1547db9fccc81e496d278eed90 (diff)
downloadmeson-3e89c30bae2265e694212a5909a553de0484dc14.zip
meson-3e89c30bae2265e694212a5909a553de0484dc14.tar.gz
meson-3e89c30bae2265e694212a5909a553de0484dc14.tar.bz2
unittests: Simplify and make test_templates more reliable
env.detect_<lang>_compiler only checks that there is a binary called whatever that returns a version. There are several cases where the found binary doesn't work: 1) gcc for ojbc[pp], when support isn't compiled in. 2) the compiler is broken (rust in appveyor somtimes) Because of that we need to call compiler.sanity_check() as well, and if we get an EnvironmentException from that skip the language Also, instead of having a long line of try: ... except: pass, roll all of the checking up into a loop using getattr(), which is less code and makes adding a new language easier
-rwxr-xr-xrun_unittests.py54
1 files changed, 8 insertions, 46 deletions
diff --git a/run_unittests.py b/run_unittests.py
index 4051e3b..ef5e48a 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -3506,53 +3506,15 @@ class AllPlatformTests(BasePlatformTests):
ninja = detect_ninja()
if ninja is None:
raise unittest.SkipTest('This test currently requires ninja. Fix this once "meson build" works.')
+
langs = ['c']
env = get_fake_env()
- try:
- env.detect_cpp_compiler(MachineChoice.HOST)
- langs.append('cpp')
- except EnvironmentException:
- pass
- try:
- env.detect_cs_compiler(MachineChoice.HOST)
- langs.append('cs')
- except EnvironmentException:
- pass
- try:
- env.detect_d_compiler(MachineChoice.HOST)
- langs.append('d')
- except EnvironmentException:
- pass
- try:
- env.detect_java_compiler(MachineChoice.HOST)
- langs.append('java')
- except EnvironmentException:
- pass
- try:
- env.detect_cuda_compiler(MachineChoice.HOST)
- langs.append('cuda')
- except EnvironmentException:
- pass
- try:
- env.detect_fortran_compiler(MachineChoice.HOST)
- langs.append('fortran')
- except EnvironmentException:
- pass
- try:
- env.detect_objc_compiler(MachineChoice.HOST)
- langs.append('objc')
- except EnvironmentException:
- pass
- try:
- env.detect_objcpp_compiler(MachineChoice.HOST)
- langs.append('objcpp')
- except EnvironmentException:
- pass
- # FIXME: omitting rust as Windows AppVeyor CI finds Rust but doesn't link correctly
- if not is_windows():
+ for l in ['cpp', 'cs', 'd', 'java', 'cuda', 'fortran', 'objc', 'objcpp', 'rust']:
try:
- env.detect_rust_compiler(MachineChoice.HOST)
- langs.append('rust')
+ comp = getattr(env, f'detect_{l}_compiler')(MachineChoice.HOST)
+ with tempfile.TemporaryDirectory() as d:
+ comp.sanity_check(d, env)
+ langs.append(l)
except EnvironmentException:
pass
@@ -3567,12 +3529,12 @@ class AllPlatformTests(BasePlatformTests):
self._run(ninja,
workdir=os.path.join(tmpdir, 'builddir'))
# test directory with existing code file
- if lang in ('c', 'cpp', 'd'):
+ if lang in {'c', 'cpp', 'd'}:
with tempfile.TemporaryDirectory() as tmpdir:
with open(os.path.join(tmpdir, 'foo.' + lang), 'w') as f:
f.write('int main(void) {}')
self._run(self.meson_command + ['init', '-b'], workdir=tmpdir)
- elif lang in ('java'):
+ elif lang in {'java'}:
with tempfile.TemporaryDirectory() as tmpdir:
with open(os.path.join(tmpdir, 'Foo.' + lang), 'w') as f:
f.write('public class Foo { public static void main() {} }')