Skip to content

Commit b65168c

Browse files
dcbakernirbheek
authored andcommitted
unit tests: correctly skip c++20 checks if the compiler doesn't support
them I can't find a supported version for AppleClang, and you need relatively recent versions of GCC and Clang for -std=c++20 to work.
1 parent d432801 commit b65168c

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

run_unittests.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
from mesonbuild.compilers.objc import AppleClangObjCCompiler
1716
import time
1817
import stat
1918
import subprocess
@@ -79,6 +78,9 @@
7978
run_configure_inprocess, run_mtest_inprocess
8079
)
8180

81+
if T.TYPE_CHECKING:
82+
from mesonbuild.compilers import Compiler
83+
8284

8385
URLOPEN_TIMEOUT = 5
8486

@@ -6273,13 +6275,16 @@ def test_compiler_check_flags_order(self):
62736275
Oargs = [arg for arg in cmd if arg.startswith('-O')]
62746276
self.assertEqual(Oargs, [Oflag, '-O0'])
62756277

6276-
def _test_stds_impl(self, testdir, compiler, p: str):
6278+
def _test_stds_impl(self, testdir, compiler: 'Compiler', p: str) -> None:
62776279
has_cpp17 = (compiler.get_id() not in {'clang', 'gcc'} or
62786280
compiler.get_id() == 'clang' and _clang_at_least(compiler, '>=5.0.0', '>=9.1') or
62796281
compiler.get_id() == 'gcc' and version_compare(compiler.version, '>=5.0.0'))
62806282
has_cpp2a_c17 = (compiler.get_id() not in {'clang', 'gcc'} or
62816283
compiler.get_id() == 'clang' and _clang_at_least(compiler, '>=6.0.0', '>=10.0') or
62826284
compiler.get_id() == 'gcc' and version_compare(compiler.version, '>=8.0.0'))
6285+
has_cpp20 = (compiler.get_id() not in {'clang', 'gcc'} or
6286+
compiler.get_id() == 'clang' and _clang_at_least(compiler, '>=10.0.0', None) or
6287+
compiler.get_id() == 'gcc' and version_compare(compiler.version, '>=10.0.0'))
62836288
has_c18 = (compiler.get_id() not in {'clang', 'gcc'} or
62846289
compiler.get_id() == 'clang' and _clang_at_least(compiler, '>=8.0.0', '>=11.0') or
62856290
compiler.get_id() == 'gcc' and version_compare(compiler.version, '>=8.0.0'))
@@ -6294,6 +6299,8 @@ def _test_stds_impl(self, testdir, compiler, p: str):
62946299
continue
62956300
elif '++2a' in v and not has_cpp2a_c17: # https://en.cppreference.com/w/cpp/compiler_support
62966301
continue
6302+
elif '++20' in v and not has_cpp20:
6303+
continue
62976304
# now C
62986305
elif '17' in v and not has_cpp2a_c17:
62996306
continue
@@ -9269,7 +9276,7 @@ def ran_in(s):
92699276
out = self._subprojects_cmd(['foreach', '--types', 'git'] + dummy_cmd)
92709277
self.assertEqual(ran_in(out), ['subprojects/sub_git'])
92719278

9272-
def _clang_at_least(compiler, minver: str, apple_minver: str) -> bool:
9279+
def _clang_at_least(compiler, minver: str, apple_minver: T.Optional[str]) -> bool:
92739280
"""
92749281
check that Clang compiler is at least a specified version, whether AppleClang or regular Clang
92759282
@@ -9289,6 +9296,8 @@ def _clang_at_least(compiler, minver: str, apple_minver: str) -> bool:
92899296
"""
92909297
if isinstance(compiler, (mesonbuild.compilers.AppleClangCCompiler,
92919298
mesonbuild.compilers.AppleClangCPPCompiler)):
9299+
if apple_minver is None:
9300+
return False
92929301
return version_compare(compiler.version, apple_minver)
92939302
return version_compare(compiler.version, minver)
92949303

0 commit comments

Comments
 (0)