From 7b81d1c394219c66d6b02360c31b8439298bde2d Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 25 Sep 2024 14:43:11 -0700 Subject: [PATCH] wip --- unittests/allplatformstests.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py index 81cd9bc53a9b..df5bea34aa8b 100644 --- a/unittests/allplatformstests.py +++ b/unittests/allplatformstests.py @@ -5010,9 +5010,11 @@ def test_configure_same_noop(self): olddata = newdata oldmtime = newmtime - def __test_multi_stds(self, extra_args: T.List[str]) -> None: + def __test_multi_stds(self, test_c: bool = True, test_objc: bool = False) -> None: + assert test_c or test_objc, 'must test something' testdir = os.path.join(self.unit_test_dir, '115 c cpp stds') - self.init(testdir, extra_args=extra_args) + self.init(testdir, extra_args=[f'-Dwith-c={str(test_c).lower()}', + f'-Dwith-objc={str(test_objc).lower()}']) # Invalid values should fail whatever compiler we have with self.assertRaises(subprocess.CalledProcessError): self.setconf('-Dc_std=invalid') @@ -5021,7 +5023,19 @@ def __test_multi_stds(self, extra_args: T.List[str]) -> None: with self.assertRaises(subprocess.CalledProcessError): self.setconf('-Dc_std=c++11') env = get_fake_env() - cc = detect_c_compiler(env, MachineChoice.HOST) + if test_c: + cc = detect_c_compiler(env, MachineChoice.HOST) + if test_objc: + objc = detect_compiler_for(env, 'objc', MachineChoice.HOST, True, '') + assert objc is not None + if test_c and cc.get_argument_syntax() != objc.get_argument_syntax(): + # The test doesn't work correctly in this case because we can + # end up with incompatible stds, like gnu89 with cl.exe for C + # and clang.exe for ObjC + return + if not test_c: + cc = objc + if cc.get_id() in {'msvc', 'clang-cl'}: # default_option should have selected those self.assertEqual(self.getconf('c_std'), 'c89') @@ -5035,26 +5049,26 @@ def __test_multi_stds(self, extra_args: T.List[str]) -> None: # The first supported std should be selected self.setconf('-Dcpp_std=gnu++11,vc++11,c++11') self.assertEqual(self.getconf('cpp_std'), 'vc++11') - elif cc.get_id() == 'gcc' or (cc.get_id() == 'clang' and not is_windows()): + elif cc.get_id() in {'gcc', 'clang'}: # default_option should have selected those self.assertEqual(self.getconf('c_std'), 'gnu89') self.assertEqual(self.getconf('cpp_std'), 'gnu++98') # The first supported std should be selected - # self.setconf('-Dcpp_std=c++11,gnu++11,vc++11') - # self.assertEqual(self.getconf('cpp_std'), 'c++11') + self.setconf('-Dcpp_std=c++11,gnu++11,vc++11') + self.assertEqual(self.getconf('cpp_std'), 'c++11') def test_c_cpp_stds(self) -> None: - self.__test_multi_stds(['-Dwith-c=true']) + self.__test_multi_stds() @skip_if_not_language('objc') @skip_if_not_language('objcpp') def test_objc_objcpp_stds(self) -> None: - self.__test_multi_stds(['-Dwith-objc=true']) + self.__test_multi_stds(test_c=False, test_objc=True) @skip_if_not_language('objc') @skip_if_not_language('objcpp') def test_c_cpp_objc_objcpp_stds(self) -> None: - self.__test_multi_stds(['-Dwith-c=true', '-Dwith-objc=true']) + self.__test_multi_stds(test_objc=True) def test_rsp_support(self): env = get_fake_env()