tests: Pass a mock C compiler to detect_cpu(), detect_cpu_family()

In some cases the desired result can be different if there are no
compilers at all. The expectations here are based on there being at
least one compiler, so reflect that by providing one; a later test
enhancement can cover the case where there are no compilers provided.

As a result of the mock any_compiler_has_define(), all that matters
will be the distinction between an empty or non-empty dict: the compiler
object itself is unused.

Signed-off-by: Simon McVittie <smcv@debian.org>
pull/12081/head
Simon McVittie 2 years ago committed by Eli Schwartz
parent 78337653fc
commit 432317bc6b
  1. 12
      unittests/internaltests.py

@ -1586,16 +1586,18 @@ class InternalTests(unittest.TestCase):
('aarch64_be', 'aarch64'),
]
cc = ClangCCompiler([], [], 'fake', MachineChoice.HOST, False, mock.Mock())
with mock.patch('mesonbuild.environment.any_compiler_has_define', mock.Mock(return_value=False)):
for test, expected in cases:
with self.subTest(test, has_define=False), mock_trial(test):
actual = mesonbuild.environment.detect_cpu_family({})
actual = mesonbuild.environment.detect_cpu_family({'c': cc})
self.assertEqual(actual, expected)
with mock.patch('mesonbuild.environment.any_compiler_has_define', mock.Mock(return_value=True)):
for test, expected in [('x86_64', 'x86'), ('aarch64', 'arm'), ('ppc', 'ppc64'), ('mips64', 'mips64')]:
with self.subTest(test, has_define=True), mock_trial(test):
actual = mesonbuild.environment.detect_cpu_family({})
actual = mesonbuild.environment.detect_cpu_family({'c': cc})
self.assertEqual(actual, expected)
def test_detect_cpu(self) -> None:
@ -1623,16 +1625,18 @@ class InternalTests(unittest.TestCase):
('aarch64_be', 'aarch64'),
]
cc = ClangCCompiler([], [], 'fake', MachineChoice.HOST, False, mock.Mock())
with mock.patch('mesonbuild.environment.any_compiler_has_define', mock.Mock(return_value=False)):
for test, expected in cases:
with self.subTest(test, has_define=False), mock_trial(test):
actual = mesonbuild.environment.detect_cpu({})
actual = mesonbuild.environment.detect_cpu({'c': cc})
self.assertEqual(actual, expected)
with mock.patch('mesonbuild.environment.any_compiler_has_define', mock.Mock(return_value=True)):
for test, expected in [('x86_64', 'i686'), ('aarch64', 'arm'), ('ppc', 'ppc64'), ('mips64', 'mips64')]:
with self.subTest(test, has_define=True), mock_trial(test):
actual = mesonbuild.environment.detect_cpu({})
actual = mesonbuild.environment.detect_cpu({'c': cc})
self.assertEqual(actual, expected)
def test_interpreter_unpicklable(self) -> None:

Loading…
Cancel
Save