diff options
author | Simon McVittie <smcv@debian.org> | 2023-08-05 11:35:56 +0100 |
---|---|---|
committer | Eli Schwartz <eschwartz93@gmail.com> | 2023-08-06 02:32:25 -0400 |
commit | 432317bc6bbfa594bbaf99e13ccb840db3903568 (patch) | |
tree | dc1138d177a0016d8a53f7f645cca41fd595953d /unittests/internaltests.py | |
parent | 78337653fce90d6745d2ce46eaba9d25ab9e18d2 (diff) | |
download | meson-432317bc6bbfa594bbaf99e13ccb840db3903568.zip meson-432317bc6bbfa594bbaf99e13ccb840db3903568.tar.gz meson-432317bc6bbfa594bbaf99e13ccb840db3903568.tar.bz2 |
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>
Diffstat (limited to 'unittests/internaltests.py')
-rw-r--r-- | unittests/internaltests.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/unittests/internaltests.py b/unittests/internaltests.py index 86a30f8..89979cd 100644 --- a/unittests/internaltests.py +++ b/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: |