diff options
| author | Xavier Claessens <xavier.claessens@collabora.com> | 2023-11-01 09:18:49 -0400 |
|---|---|---|
| committer | Xavier Claessens <xclaesse@gmail.com> | 2025-05-31 10:07:06 -0400 |
| commit | bf2075eca3c35a02b58fe44c9b6964566473894d (patch) | |
| tree | 0a4b2a1d1b59620a635b6e7f5da90cc1f66c1523 /unittests | |
| parent | 474d77d005512f37710a84f1e809e0878cc22713 (diff) | |
| download | meson-bf2075eca3c35a02b58fe44c9b6964566473894d.tar.gz | |
cargo: Do not convert cfg() to Meson AST
We'll need to evaluate those expressions before generating the AST.
Instead take a config key-value dictionary and evaluate the expression
to return a boolean.
Diffstat (limited to 'unittests')
| -rw-r--r-- | unittests/cargotests.py | 69 |
1 files changed, 19 insertions, 50 deletions
diff --git a/unittests/cargotests.py b/unittests/cargotests.py index 90b7f867f..eeb676bd2 100644 --- a/unittests/cargotests.py +++ b/unittests/cargotests.py @@ -151,60 +151,29 @@ class CargoCfgTest(unittest.TestCase): with self.subTest(): self.assertEqual(cfg.parse(iter(cfg.lexer(data))), expected) - def test_ir_to_meson(self) -> None: - build = builder.Builder('') - HOST_MACHINE = build.identifier('host_machine') - + def test_eval_ir(self) -> None: + d = { + 'target_os': 'unix', + 'unix': '', + } cases = [ - ('target_os = "windows"', - build.equal(build.method('system', HOST_MACHINE), - build.string('windows'))), - ('target_arch = "x86"', - build.equal(build.method('cpu_family', HOST_MACHINE), - build.string('x86'))), - ('target_family = "unix"', - build.equal(build.method('system', HOST_MACHINE), - build.string('unix'))), - ('not(target_arch = "x86")', - build.not_(build.equal( - build.method('cpu_family', HOST_MACHINE), - build.string('x86')))), - ('any(target_arch = "x86", target_arch = "x86_64")', - build.or_( - build.equal(build.method('cpu_family', HOST_MACHINE), - build.string('x86')), - build.equal(build.method('cpu_family', HOST_MACHINE), - build.string('x86_64')))), - ('any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")', - build.or_( - build.equal(build.method('cpu_family', HOST_MACHINE), - build.string('x86')), - build.or_( - build.equal(build.method('cpu_family', HOST_MACHINE), - build.string('x86_64')), - build.equal(build.method('cpu_family', HOST_MACHINE), - build.string('aarch64'))))), - ('all(target_arch = "x86", target_arch = "x86_64")', - build.and_( - build.equal(build.method('cpu_family', HOST_MACHINE), - build.string('x86')), - build.equal(build.method('cpu_family', HOST_MACHINE), - build.string('x86_64')))), - ('all(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")', - build.and_( - build.equal(build.method('cpu_family', HOST_MACHINE), - build.string('x86')), - build.and_( - build.equal(build.method('cpu_family', HOST_MACHINE), - build.string('x86_64')), - build.equal(build.method('cpu_family', HOST_MACHINE), - build.string('aarch64'))))), - ('all()', build.bool(True)), - ('any()', build.bool(False)), + ('target_os = "windows"', False), + ('target_os = "unix"', True), + ('doesnotexist = "unix"', False), + ('not(target_os = "windows")', True), + ('any(target_os = "windows", target_arch = "x86_64")', False), + ('any(target_os = "windows", target_os = "unix")', True), + ('all(target_os = "windows", target_os = "unix")', False), + ('all(not(target_os = "windows"), target_os = "unix")', True), + ('any(unix, windows)', True), + ('all()', True), + ('any()', False), + ('cfg(unix)', True), + ('cfg(windows)', False), ] for data, expected in cases: with self.subTest(): - value = cfg.ir_to_meson(cfg.parse(iter(cfg.lexer(data))), build) + value = cfg.eval_cfg(data, d) self.assertEqual(value, expected) class CargoLockTest(unittest.TestCase): |
