aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2024-06-02 16:45:42 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2024-06-02 17:43:50 +0300
commit4cc2e2171a7a6452da6ee0ec336ecb0e77f19791 (patch)
tree5236f507738450adc0f2f3e657414c450120f597
parentdaa058e90793e6ff8c8e1a3fa14a88c0167d8561 (diff)
downloadmeson-4cc2e2171a7a6452da6ee0ec336ecb0e77f19791.zip
meson-4cc2e2171a7a6452da6ee0ec336ecb0e77f19791.tar.gz
meson-4cc2e2171a7a6452da6ee0ec336ecb0e77f19791.tar.bz2
Create a directory for machine files used in unit tests.
-rw-r--r--unittests/allplatformstests.py50
-rw-r--r--unittests/machinefiles/constant1.txt2
-rw-r--r--unittests/machinefiles/constant2.txt13
3 files changed, 31 insertions, 34 deletions
diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py
index 9c9f616..63445ec 100644
--- a/unittests/allplatformstests.py
+++ b/unittests/allplatformstests.py
@@ -25,6 +25,7 @@ import mesonbuild.dependencies.factory
import mesonbuild.envconfig
import mesonbuild.environment
import mesonbuild.coredata
+import mesonbuild.machinefile
import mesonbuild.modules.gnome
from mesonbuild.mesonlib import (
BuildDirLock, MachineChoice, is_windows, is_osx, is_cygwin, is_dragonflybsd,
@@ -61,6 +62,8 @@ from run_tests import (
from .baseplatformtests import BasePlatformTests
from .helpers import *
+UNIT_MACHINEFILE_DIR = Path(__file__).parent / 'machinefiles'
+
@contextmanager
def temp_filename():
'''A context manager which provides a filename to an empty temporary file.
@@ -4111,40 +4114,19 @@ class AllPlatformTests(BasePlatformTests):
self._check_coverage_files()
def test_cross_file_constants(self):
- with temp_filename() as crossfile1, temp_filename() as crossfile2:
- with open(crossfile1, 'w', encoding='utf-8') as f:
- f.write(textwrap.dedent(
- '''
- [constants]
- compiler = 'gcc'
- '''))
- with open(crossfile2, 'w', encoding='utf-8') as f:
- f.write(textwrap.dedent(
- '''
- [constants]
- toolchain = '/toolchain/'
- common_flags = ['--sysroot=' + toolchain / 'sysroot']
-
- [properties]
- c_args = common_flags + ['-DSOMETHING']
- cpp_args = c_args + ['-DSOMETHING_ELSE']
- rel_to_src = '@GLOBAL_SOURCE_ROOT@' / 'tool'
- rel_to_file = '@DIRNAME@' / 'tool'
- no_escaping = '@@DIRNAME@@' / 'tool'
-
- [binaries]
- c = toolchain / compiler
- '''))
-
- values = mesonbuild.coredata.parse_machine_files([crossfile1, crossfile2], self.builddir)
- self.assertEqual(values['binaries']['c'], '/toolchain/gcc')
- self.assertEqual(values['properties']['c_args'],
- ['--sysroot=/toolchain/sysroot', '-DSOMETHING'])
- self.assertEqual(values['properties']['cpp_args'],
- ['--sysroot=/toolchain/sysroot', '-DSOMETHING', '-DSOMETHING_ELSE'])
- self.assertEqual(values['properties']['rel_to_src'], os.path.join(self.builddir, 'tool'))
- self.assertEqual(values['properties']['rel_to_file'], os.path.join(os.path.dirname(crossfile2), 'tool'))
- self.assertEqual(values['properties']['no_escaping'], os.path.join(f'@{os.path.dirname(crossfile2)}@', 'tool'))
+ crossfile1 = UNIT_MACHINEFILE_DIR / 'constant1.txt'
+ crossfile2 = UNIT_MACHINEFILE_DIR / 'constant2.txt'
+ values = mesonbuild.machinefile.parse_machine_files([crossfile1,
+ crossfile2],
+ self.builddir)
+ self.assertEqual(values['binaries']['c'], '/toolchain/gcc')
+ self.assertEqual(values['properties']['c_args'],
+ ['--sysroot=/toolchain/sysroot', '-DSOMETHING'])
+ self.assertEqual(values['properties']['cpp_args'],
+ ['--sysroot=/toolchain/sysroot', '-DSOMETHING', '-DSOMETHING_ELSE'])
+ self.assertEqual(values['properties']['rel_to_src'], os.path.join(self.builddir, 'tool'))
+ self.assertEqual(values['properties']['rel_to_file'], os.path.join(os.path.dirname(crossfile2), 'tool'))
+ self.assertEqual(values['properties']['no_escaping'], os.path.join(f'@{os.path.dirname(crossfile2)}@', 'tool'))
@skipIf(is_windows(), 'Directory cleanup fails for some reason')
def test_wrap_git(self):
diff --git a/unittests/machinefiles/constant1.txt b/unittests/machinefiles/constant1.txt
new file mode 100644
index 0000000..eeba7cb
--- /dev/null
+++ b/unittests/machinefiles/constant1.txt
@@ -0,0 +1,2 @@
+[constants]
+compiler = 'gcc'
diff --git a/unittests/machinefiles/constant2.txt b/unittests/machinefiles/constant2.txt
new file mode 100644
index 0000000..226dcc8
--- /dev/null
+++ b/unittests/machinefiles/constant2.txt
@@ -0,0 +1,13 @@
+[constants]
+toolchain = '/toolchain/'
+common_flags = ['--sysroot=' + toolchain / 'sysroot']
+
+[properties]
+c_args = common_flags + ['-DSOMETHING']
+cpp_args = c_args + ['-DSOMETHING_ELSE']
+rel_to_src = '@GLOBAL_SOURCE_ROOT@' / 'tool'
+rel_to_file = '@DIRNAME@' / 'tool'
+no_escaping = '@@DIRNAME@@' / 'tool'
+
+[binaries]
+c = toolchain / compiler