diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2021-08-30 10:37:41 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2021-08-30 10:37:41 -0700 |
commit | b8cdae70033843e054ab6580fdeec1c08693c645 (patch) | |
tree | 39af6c809a3697ef02856c020895f4fd8a5b4dea /unittests/internaltests.py | |
parent | 84fff3521a8c691c6e3f512a83970f6466606b27 (diff) | |
download | meson-b8cdae70033843e054ab6580fdeec1c08693c645.zip meson-b8cdae70033843e054ab6580fdeec1c08693c645.tar.gz meson-b8cdae70033843e054ab6580fdeec1c08693c645.tar.bz2 |
unittests: add tests for detect_cpu
Same thing, but for the more specific cases
Diffstat (limited to 'unittests/internaltests.py')
-rw-r--r-- | unittests/internaltests.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/unittests/internaltests.py b/unittests/internaltests.py index bc6bca5..ad86062 100644 --- a/unittests/internaltests.py +++ b/unittests/internaltests.py @@ -1478,3 +1478,38 @@ class InternalTests(unittest.TestCase): with self.subTest(test, has_define=True), mock_trial(test): actual = mesonbuild.environment.detect_cpu_family({}) self.assertEqual(actual, expected) + + def test_detect_cpu(self) -> None: + + @contextlib.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) |