Skip to content

Commit 21ae1bf

Browse files
smcvmatoro
authored andcommitted
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 <[email protected]>
1 parent 82d41db commit 21ae1bf

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

unittests/internaltests.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,16 +1596,18 @@ def mock_trial(value: str) -> T.Iterable[None]:
15961596
('aarch64_be', 'aarch64'),
15971597
]
15981598

1599+
cc = ClangCCompiler([], [], 'fake', MachineChoice.HOST, False, mock.Mock())
1600+
15991601
with mock.patch('mesonbuild.environment.any_compiler_has_define', mock.Mock(return_value=False)):
16001602
for test, expected in cases:
16011603
with self.subTest(test, has_define=False), mock_trial(test):
1602-
actual = mesonbuild.environment.detect_cpu_family({})
1604+
actual = mesonbuild.environment.detect_cpu_family({'c': cc})
16031605
self.assertEqual(actual, expected)
16041606

16051607
with mock.patch('mesonbuild.environment.any_compiler_has_define', mock.Mock(return_value=True)):
16061608
for test, expected in [('x86_64', 'x86'), ('aarch64', 'arm'), ('ppc', 'ppc64'), ('mips64', 'mips64')]:
16071609
with self.subTest(test, has_define=True), mock_trial(test):
1608-
actual = mesonbuild.environment.detect_cpu_family({})
1610+
actual = mesonbuild.environment.detect_cpu_family({'c': cc})
16091611
self.assertEqual(actual, expected)
16101612

16111613
def test_detect_cpu(self) -> None:
@@ -1633,16 +1635,18 @@ def mock_trial(value: str) -> T.Iterable[None]:
16331635
('aarch64_be', 'aarch64'),
16341636
]
16351637

1638+
cc = ClangCCompiler([], [], 'fake', MachineChoice.HOST, False, mock.Mock())
1639+
16361640
with mock.patch('mesonbuild.environment.any_compiler_has_define', mock.Mock(return_value=False)):
16371641
for test, expected in cases:
16381642
with self.subTest(test, has_define=False), mock_trial(test):
1639-
actual = mesonbuild.environment.detect_cpu({})
1643+
actual = mesonbuild.environment.detect_cpu({'c': cc})
16401644
self.assertEqual(actual, expected)
16411645

16421646
with mock.patch('mesonbuild.environment.any_compiler_has_define', mock.Mock(return_value=True)):
16431647
for test, expected in [('x86_64', 'i686'), ('aarch64', 'arm'), ('ppc', 'ppc64'), ('mips64', 'mips64')]:
16441648
with self.subTest(test, has_define=True), mock_trial(test):
1645-
actual = mesonbuild.environment.detect_cpu({})
1649+
actual = mesonbuild.environment.detect_cpu({'c': cc})
16461650
self.assertEqual(actual, expected)
16471651

16481652
def test_interpreter_unpicklable(self) -> None:

0 commit comments

Comments
 (0)