tests: Add tests for cross file exe_wrapper
tests needs_exe wrapper but doesn't have one, !needs_exe_wrapper, and
needs_exe_wrapper and has one.
@@ -40,6 +40,7 @@ from contextlib import contextmanager
from glob import glob
from pathlib import (PurePath, Path)
from distutils.dir_util import copy_tree
+import typing
import mesonbuild.mlog
import mesonbuild.depfile
@@ -7545,7 +7546,10 @@ class CrossFileTests(BasePlatformTests):
This is mainly aimed to testing overrides from cross files.
"""
- def _cross_file_generator(self) -> str:
+ def _cross_file_generator(self, *, needs_exe_wrapper: bool = False,
+ exe_wrapper: typing.Optional[typing.List[str]] = None) -> str:
+ if is_windows():
+ raise unittest.SkipTest('Cannot run this test on non-mingw/non-cygwin windows')
if is_sunos():
cc = 'gcc'
else:
@@ -7558,13 +7562,59 @@ class CrossFileTests(BasePlatformTests):
strip = '/usr/bin/ar'
[properties]
+ needs_exe_wrapper = {}
+ {}
[host_machine]
system = 'linux'
cpu_family = 'x86'
cpu = 'i686'
endian = 'little'
- """.format(cc))
+ """.format(cc, needs_exe_wrapper,
+ 'exe_wrapper = {}'.format(str(exe_wrapper))
+ if exe_wrapper is not None else ''))
+
+ def test_needs_exe_wrapper_true(self):
+ testdir = os.path.join(self.common_test_dir, '1 trivial')
+ with tempfile.TemporaryDirectory() as d:
+ p = Path(d) / 'crossfile'
+ with p.open('wt') as f:
+ f.write(self._cross_file_generator(needs_exe_wrapper=True))
+ self.init(testdir, extra_args=['--cross-file=' + str(p)])
+ out = self.run_target('test')
+ self.assertRegex(out, r'Skipped:\s*1\n')
+
+ def test_needs_exe_wrapper_false(self):
+ testdir = os.path.join(self.common_test_dir, '1 trivial')
+ with tempfile.TemporaryDirectory() as d:
+ p = Path(d) / 'crossfile'
+ with p.open('wt') as f:
+ f.write(self._cross_file_generator(needs_exe_wrapper=False))
+ self.init(testdir, extra_args=['--cross-file=' + str(p)])
+ out = self.run_target('test')
+ self.assertNotRegex(out, r'Skipped:\s*1\n')
+
+ def test_needs_exe_wrapper_true_wrapper(self):
+ testdir = os.path.join(self.common_test_dir, '1 trivial')
+ with tempfile.TemporaryDirectory() as d:
+ s = Path(d) / 'wrapper.py'
+ with s.open('wt') as f:
+ f.write(textwrap.dedent('''
+ #!/usr/bin/env python3
+ import subprocess
+ import sys
+
+ return subprocess.run(sys.argv[1:]).returnncode
+ '''))
+ p = Path(d) / 'crossfile'
+ with p.open('wt') as f:
+ f.write(self._cross_file_generator(
+ needs_exe_wrapper=True,
+ exe_wrapper=[str(s)]))
+
+ self.init(testdir, extra_args=['--cross-file=' + str(p)])
+ out = self.run_target('test')
+ self.assertNotRegex(out, r'Skipped:\s*1\n')
# The test uses mocking and thus requires that the current process is the
# one to run the Meson steps. If we are using an external test executable
