aboutsummaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2023-08-30 12:04:09 -0700
committerGitHub <noreply@github.com>2023-08-30 12:04:09 -0700
commit08d83a4a97e66c83d23f10f853d6948921ad144c (patch)
treece6b7197fcf7d450419f699f2d06aa1bf31343fa /unittests
parent494bdbd3345d1c2d20cf2520249962bd32fc61e6 (diff)
parent82a8c72187f844713618526ed3890d7b313b2065 (diff)
downloadmeson-08d83a4a97e66c83d23f10f853d6948921ad144c.zip
meson-08d83a4a97e66c83d23f10f853d6948921ad144c.tar.gz
meson-08d83a4a97e66c83d23f10f853d6948921ad144c.tar.bz2
Merge pull request #10332 from xclaesse/std-opt
c_std, cpp_std: Change to a list of desired versions in preference order
Diffstat (limited to 'unittests')
-rw-r--r--unittests/allplatformstests.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py
index b5252f7..acab026 100644
--- a/unittests/allplatformstests.py
+++ b/unittests/allplatformstests.py
@@ -4820,3 +4820,36 @@ class AllPlatformTests(BasePlatformTests):
self.assertNotEqual(olddata, newdata)
olddata = newdata
oldmtime = newmtime
+
+ def test_c_cpp_stds(self):
+ testdir = os.path.join(self.unit_test_dir, '114 c cpp stds')
+ self.init(testdir)
+ # Invalid values should fail whatever compiler we have
+ with self.assertRaises(subprocess.CalledProcessError):
+ self.setconf('-Dc_std=invalid')
+ with self.assertRaises(subprocess.CalledProcessError):
+ self.setconf('-Dc_std=c89,invalid')
+ with self.assertRaises(subprocess.CalledProcessError):
+ self.setconf('-Dc_std=c++11')
+ env = get_fake_env()
+ cc = detect_c_compiler(env, MachineChoice.HOST)
+ if cc.get_id() == 'msvc':
+ # default_option should have selected those
+ self.assertEqual(self.getconf('c_std'), 'c89')
+ self.assertEqual(self.getconf('cpp_std'), 'vc++11')
+ # This is deprecated but works for C
+ self.setconf('-Dc_std=gnu99')
+ self.assertEqual(self.getconf('c_std'), 'c99')
+ # C++ however never accepted that fallback
+ with self.assertRaises(subprocess.CalledProcessError):
+ self.setconf('-Dcpp_std=gnu++11')
+ # 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':
+ # 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')