diff options
| author | Dylan Baker <dylan@pnwbakers.com> | 2024-09-12 09:27:31 -0700 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2025-01-27 09:38:53 -0800 |
| commit | d6e54b499cb2b7a533e6b1ad97637b8155c0a66c (patch) | |
| tree | a23d3fe0952f06c70ffc677045e1f83c61ebafbb | |
| parent | 18331db7c1b32e6a8771f0f058c1dd8fce52a1b7 (diff) | |
| download | meson-d6e54b499cb2b7a533e6b1ad97637b8155c0a66c.tar.gz | |
unit tests: Test ObjC and ObjC++ as well as C and C++
This tests ObjC and ObjC++ both with and without C enabled. I did this
because I ran into issues where ObjC only worked when C was enabled, and
then a later bug where C was disabled, due to the fact that C and ObjC
both use `c_std` and not `objc_std`.
| -rw-r--r-- | test cases/unit/116 c cpp stds/meson.build | 21 | ||||
| -rw-r--r-- | test cases/unit/116 c cpp stds/meson.options | 5 | ||||
| -rw-r--r-- | unittests/allplatformstests.py | 35 |
3 files changed, 52 insertions, 9 deletions
diff --git a/test cases/unit/116 c cpp stds/meson.build b/test cases/unit/116 c cpp stds/meson.build index 0b15efc08..fb68af610 100644 --- a/test cases/unit/116 c cpp stds/meson.build +++ b/test cases/unit/116 c cpp stds/meson.build @@ -1,6 +1,17 @@ -project('c cpp stds', 'c', 'cpp', - default_options: [ - 'c_std=gnu89,c89', - 'cpp_std=gnu++98,vc++11', - ], +# SPDX-License-Identifier: Apache-2.0 +# Copyright © 2024 Intel Corporation + +project( + 'c cpp stds', + default_options: [ + 'c_std=gnu89,c89', + 'cpp_std=gnu++98,vc++11', + ], ) + +if get_option('with-c') + add_languages('c', 'cpp', native : false) +endif +if get_option('with-objc') + add_languages('objc', 'objcpp', native : false) +endif diff --git a/test cases/unit/116 c cpp stds/meson.options b/test cases/unit/116 c cpp stds/meson.options new file mode 100644 index 000000000..704075881 --- /dev/null +++ b/test cases/unit/116 c cpp stds/meson.options @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright © 2024 Intel Corporation + +option('with-c', type : 'boolean', value : false) +option('with-objc', type : 'boolean', value : false) diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py index d5c126e50..7c2d3ba61 100644 --- a/unittests/allplatformstests.py +++ b/unittests/allplatformstests.py @@ -5043,9 +5043,11 @@ class AllPlatformTests(BasePlatformTests): olddata = newdata oldmtime = newmtime - def test_c_cpp_stds(self): + 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, '116 c cpp stds') - self.init(testdir) + 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') @@ -5054,7 +5056,19 @@ class AllPlatformTests(BasePlatformTests): 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') @@ -5068,7 +5082,7 @@ class AllPlatformTests(BasePlatformTests): # 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') @@ -5076,6 +5090,19 @@ class AllPlatformTests(BasePlatformTests): 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() + + @skip_if_not_language('objc') + @skip_if_not_language('objcpp') + def test_objc_objcpp_stds(self) -> None: + 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(test_objc=True) + def test_rsp_support(self): env = get_fake_env() cc = detect_c_compiler(env, MachineChoice.HOST) |
