diff --git a/test/10_cpp_standards/cibuildwheel_test.py b/test/10_cpp_standards/cibuildwheel_test.py index ef53c4ad..2fc172e0 100644 --- a/test/10_cpp_standards/cibuildwheel_test.py +++ b/test/10_cpp_standards/cibuildwheel_test.py @@ -6,53 +6,55 @@ import pytest import utils +project_dir = os.path.dirname(__file__) + def test_cpp11(tmp_path): - add_env = {"CIBW_SKIP": "cp27-win*", "CIBW_ENVIRONMENT": "STANDARD=11"} - # VC for python 2.7 do not support modern standards - if utils.platform == "macos": - add_env["MACOSX_DEPLOYMENT_TARGET"] = "10.9" - project_dir = os.path.dirname(__file__) - # this test checks if c++11 standard is supported. + # This test checks that the C++11 standard is supported + + add_env = {'CIBW_SKIP': 'cp27-win*', 'CIBW_ENVIRONMENT': 'STANDARD=11'} + # VC++ for Python 2.7 does not support modern standards + if utils.platform == 'macos': + add_env['MACOSX_DEPLOYMENT_TARGET'] = '10.9' actual_wheels = utils.cibuildwheel_run(project_dir, add_env=add_env) - expected_wheels = [x for x in utils.expected_wheels('spam', '0.1.0', - macosx_deployment_target="10.9") if "cp27-cp27m-win" not in x] + expected_wheels = [x for x in utils.expected_wheels( + 'spam', '0.1.0', macosx_deployment_target='10.9') + if 'cp27-cp27m-win' not in x] assert set(actual_wheels) == set(expected_wheels) def test_cpp14(): - add_env = {"CIBW_SKIP": "cp27-win* cp35-win*", "CIBW_ENVIRONMENT": "STANDARD=14"} - # VC for python 2.7 do not support modern standards - # manylinux1 docker image do not support compilers with standards newer than c++11 - # python 3.4 and 3.5 are compiled with MSVC 10. which not support c++14 - if utils.platform == "macos": - add_env["MACOSX_DEPLOYMENT_TARGET"] = "10.9" - project_dir = os.path.dirname(__file__) - # this test checks if c++14 standard is supported. + # This test checks that the C++14 standard is supported + + add_env = {'CIBW_SKIP': 'cp27-win* cp35-win*', 'CIBW_ENVIRONMENT': 'STANDARD=14'} + # VC++ for Python 2.7 does not support modern standards + # The manylinux1 docker image does not have a compiler which supports C++11 + # Python 3.4 and 3.5 are compiled with MSVC 10, which does not support C++14 + if utils.platform == 'macos': + add_env['MACOSX_DEPLOYMENT_TARGET'] = '10.9' actual_wheels = utils.cibuildwheel_run(project_dir, add_env=add_env) expected_wheels = [x for x in utils.expected_wheels( - 'spam', '0.1.0', macosx_deployment_target="10.9") - if "cp27-cp27m-win" not in x and "cp35-cp35m-win" not in x] + 'spam', '0.1.0', macosx_deployment_target='10.9') + if 'cp27-cp27m-win' not in x and 'cp35-cp35m-win' not in x] assert set(actual_wheels) == set(expected_wheels) + def test_cpp17(): - # python 2.7 use `register` keyword which is forbidden in c++17 standard - # manylinux1 docker image do not support compilers with standards newer than c++11 - # python 3.4 and 3.5 are compiled with MSVC 10. which not support c++17 - if os.environ.get("APPVEYOR_BUILD_WORKER_IMAGE", "") == "Visual Studio 2015": - pytest.skip("Visual Studio 2015 does not support c++17") + # This test checks that the C++17 standard is supported - add_env = {"CIBW_SKIP": "cp27-win* cp35-win*", "CIBW_ENVIRONMENT": "STANDARD=17"} - if utils.platform == "macos": - add_env["MACOSX_DEPLOYMENT_TARGET"] = "10.13" + # Python 2.7 uses the `register` keyword which is forbidden in the C++17 standard + # The manylinux1 docker image does not have a compiler which supports C++11 + # Python 3.4 and 3.5 are compiled with MSVC 10, which does not support C++17 + if os.environ.get('APPVEYOR_BUILD_WORKER_IMAGE', '') == 'Visual Studio 2015': + pytest.skip('Visual Studio 2015 does not support C++17') - project_dir = os.path.dirname(__file__) - # this test checks if c++17 standard is supported. + add_env = {'CIBW_SKIP': 'cp27-win* cp35-win*', 'CIBW_ENVIRONMENT': 'STANDARD=17'} + if utils.platform == 'macos': + add_env['MACOSX_DEPLOYMENT_TARGET'] = '10.13' actual_wheels = utils.cibuildwheel_run(project_dir, add_env=add_env) - expected_wheels = [x for x in utils.expected_wheels('spam', '0.1.0', - macosx_deployment_target="10.13") - if "cp27-cp27m-win" not in x and "cp35-cp35m-win" not in x] + expected_wheels = [x for x in utils.expected_wheels( + 'spam', '0.1.0', macosx_deployment_target='10.13') + if 'cp27-cp27m-win' not in x and 'cp35-cp35m-win' not in x] assert set(actual_wheels) == set(expected_wheels) - diff --git a/test/10_cpp_standards/setup.py b/test/10_cpp_standards/setup.py index 85e9492c..969ca39b 100644 --- a/test/10_cpp_standards/setup.py +++ b/test/10_cpp_standards/setup.py @@ -6,7 +6,7 @@ standard = os.environ["STANDARD"] language_standard = "/std:c++" + standard if platform.system() == "Windows" else "-std=c++" + standard -extra_compile_args=[language_standard, "-DSTANDARD=" + standard] +extra_compile_args = [language_standard, "-DSTANDARD=" + standard] if standard == "17": if platform.system() == "Windows": diff --git a/test/10_cpp_standards/spam.cpp b/test/10_cpp_standards/spam.cpp index d619c54b..f9b56d07 100644 --- a/test/10_cpp_standards/spam.cpp +++ b/test/10_cpp_standards/spam.cpp @@ -1,18 +1,18 @@ #include #include -#if STANDARD == 11 -#include -#elif STANDARD == 14 -int a = 100'000; -#elif STANDARD == 17 -#include -auto a = std::pair(5.0, false); -#else -#error Standard needed -#endif -#define STR_HELPER(x) #x -#define STR(x) STR_HELPER(x) +// Depending on the requested standard, use a modern C++ feature +// that was introduced in that standard. +#if STANDARD == 11 + #include +#elif STANDARD == 14 + int a = 100'000; +#elif STANDARD == 17 + #include + auto a = std::pair(5.0, false); +#else + #error Standard needed +#endif static PyObject * spam_system(PyObject *self, PyObject *args) diff --git a/test/shared/utils.py b/test/shared/utils.py index 3615a3db..9ed730ff 100644 --- a/test/shared/utils.py +++ b/test/shared/utils.py @@ -53,6 +53,8 @@ def cibuildwheel_run(project_path, env=None, add_env=None, output_dir=None): ''' if env is None: env = os.environ.copy() + # If present in the host environment, remove the MACOSX_DEPLOYMENT_TARGET for consistency + env.pop('MACOSX_DEPLOYMENT_TARGET', None) if add_env is not None: env.update(add_env) @@ -94,20 +96,15 @@ def expected_wheels(package_name, package_version, manylinux_versions=['manylinu return ['win32', 'win_amd64'] elif platform == 'macos': - if macosx_deployment_target is not None: - tag = macosx_deployment_target.replace(".", "_") - tag1 = macosx_deployment_target.replace(".", "_") - else: - tag = os.environ.get("MACOSX_DEPLOYMENT_TARGET", "10_6").replace(".", "_") - tag1 = os.environ.get("MACOSX_DEPLOYMENT_TARGET", "10_9").replace(".", "_") def get_platform_tags(python_abi_tag): if python_abi_tag == 'cp38-cp38': - return ['macosx_' + tag1 + '_x86_64'] + return ['macosx_' + (macosx_deployment_target or "10.9").replace(".", "_") + '_x86_64'] else: - return ['macosx_' + tag + '_intel'] + return ['macosx_' + (macosx_deployment_target or "10.6").replace(".", "_") + '_intel'] else: raise Exception('unsupported platform') + templates = [] for python_abi_tag in python_abi_tags: for platform_tag in get_platform_tags(python_abi_tag):