unittests: add tests for detect_cpu

Same thing, but for the more specific cases
pull/9295/head
Dylan Baker 4 years ago committed by Nirbheek Chauhan
parent 80dd2dec97
commit d7b2ead292
  1. 35
      run_unittests.py

@ -1763,6 +1763,41 @@ class InternalTests(unittest.TestCase):
actual = mesonbuild.environment.detect_cpu_family({})
self.assertEqual(actual, expected)
def test_detect_cpu(self) -> None:
@contextmanager
def mock_trial(value: str) -> T.Iterable[None]:
"""Mock all of the ways we could get the trial at once."""
mocked = mock.Mock(return_value=value)
with mock.patch('mesonbuild.environment.detect_windows_arch', mocked), \
mock.patch('mesonbuild.environment.platform.processor', mocked), \
mock.patch('mesonbuild.environment.platform.machine', mocked):
yield
cases = [
('amd64', 'x86_64'),
('x64', 'x86_64'),
('i86pc', 'x86_64'),
('earm', 'arm'),
('mips64el', 'mips64'),
('mips64', 'mips64'),
('mips', 'mips'),
('mipsel', 'mips'),
]
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({})
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')]:
with self.subTest(test, has_define=True), mock_trial(test):
actual = mesonbuild.environment.detect_cpu({})
self.assertEqual(actual, expected)
@unittest.skipIf(is_tarball(), 'Skipping because this is a tarball release')
class DataTests(unittest.TestCase):

Loading…
Cancel
Save