diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000..a2627c7972 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,81 @@ +name: CI + +on: + workflow_dispatch: + pull_request: + push: + branches: + - master + - stable + - v* + +jobs: + standard: + strategy: + fail-fast: false + matrix: + os: [ubuntu, windows, macos] + python: + - 2.7 + - 3.5 + - 3.8 + - 3.9-dev + - pypy2 + - pypy3 + + include: + - os: ubuntu + python: 3.6 + - os: macos + python: 3.7 + + exclude: + # Currently 32bit only, and we build 64bit + - os: windows + python: pypy2 + - os: windows + python: pypy3 + + # Currently can't build due to warning, fixed in CPython > 3.9b5 + - os: macos + python: 3.9-dev + + # Currently broken on embed_test + - os: windows + python: 3.8 + - os: windows + python: 3.9-dev + + name: Python ${{ matrix.python }} on ${{ matrix.os }} + runs-on: ${{ matrix.os }}-latest + + steps: + - uses: actions/checkout@v2 + + - name: Setup Python ${{ matrix.python }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python }} + + - name: Prepare env + run: python -m pip install -r tests/requirements.txt + + - name: Configure + shell: bash + run: > + cmake -S . -B build + -DPYBIND11_WERROR=ON + -DDOWNLOAD_CATCH=ON + -DPYTHON_EXECUTABLE=$(python -c "import sys; print(sys.executable)") + + - name: Build + run: cmake --build build -j 2 + + - name: Python tests + run: cmake --build build --target pytest -j 2 -v + + - name: C++ tests + run: cmake --build build --target cpptest -j 2 -v + + - name: Interface test + run: cmake --build build --target test_cmake_build diff --git a/.gitignore b/.gitignore index 244bbcaa7a..4dca42ab7e 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,4 @@ MANIFEST sosize-*.txt pybind11Config*.cmake pybind11Targets.cmake +/*env* diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e4aba75674..b1c72b76ac 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -151,6 +151,14 @@ function(pybind11_enable_warnings target_name) target_compile_options(${target_name} PRIVATE -Werror) endif() endif() + + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND PYTHON_VERSION VERSION_LESS 3.0) + if(CMAKE_CXX_STANDARD STREQUAL "14") + target_compile_options(${target_name} PUBLIC -Wno-deprecated-register) + elseif(NOT CMAKE_CXX_STANDARD VERSION_LESS 17) + target_compile_options(${target_name} PUBLIC -Wno-register) + endif() + endif() endfunction() set(test_targets pybind11_tests) @@ -203,10 +211,10 @@ foreach(target ${test_targets}) # Always write the output file directly into the 'tests' directory (even on MSVC) if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY) - set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${testdir}) + set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${testdir}") foreach(config ${CMAKE_CONFIGURATION_TYPES}) string(TOUPPER ${config} config) - set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${config} ${testdir}) + set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${config} "${testdir}") endforeach() endif() endforeach() diff --git a/tests/requirements.txt b/tests/requirements.txt new file mode 100644 index 0000000000..37e06ca8df --- /dev/null +++ b/tests/requirements.txt @@ -0,0 +1,3 @@ +--extra-index-url https://antocuni.github.io/pypy-wheels/manylinux2010/ +numpy; platform_python_implementation!="PyPy" or sys_platform!="darwin" or python_version<"3.0" +pytest diff --git a/tests/test_cmake_build/CMakeLists.txt b/tests/test_cmake_build/CMakeLists.txt index c9b5fcb2e7..cf9a9ca9ff 100644 --- a/tests/test_cmake_build/CMakeLists.txt +++ b/tests/test_cmake_build/CMakeLists.txt @@ -13,6 +13,7 @@ function(pybind11_add_build_test name) set(build_options "-DCMAKE_PREFIX_PATH=${PROJECT_BINARY_DIR}/mock_install" "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" "-DPYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE}" + "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}" "-DPYBIND11_CPP_STANDARD=${PYBIND11_CPP_STANDARD}") if(NOT ARG_INSTALL) list(APPEND build_options "-DPYBIND11_PROJECT_DIR=${PROJECT_SOURCE_DIR}") diff --git a/tests/test_embed/CMakeLists.txt b/tests/test_embed/CMakeLists.txt index 8b4f1f843e..c5aa7c6c5e 100644 --- a/tests/test_embed/CMakeLists.txt +++ b/tests/test_embed/CMakeLists.txt @@ -17,25 +17,29 @@ add_executable(test_embed catch.cpp test_interpreter.cpp ) -target_include_directories(test_embed PRIVATE ${CATCH_INCLUDE_DIR}) +target_include_directories(test_embed PRIVATE "${CATCH_INCLUDE_DIR}") pybind11_enable_warnings(test_embed) if(NOT CMAKE_VERSION VERSION_LESS 3.0) target_link_libraries(test_embed PRIVATE pybind11::embed) else() - target_include_directories(test_embed PRIVATE ${PYBIND11_INCLUDE_DIR} ${PYTHON_INCLUDE_DIRS}) - target_compile_options(test_embed PRIVATE ${PYBIND11_CPP_STANDARD}) - target_link_libraries(test_embed PRIVATE ${PYTHON_LIBRARIES}) + target_include_directories(test_embed PRIVATE "${PYBIND11_INCLUDE_DIR}" "${PYTHON_INCLUDE_DIRS}") + target_compile_options(test_embed PRIVATE "${PYBIND11_CPP_STANDARD}") + target_link_libraries(test_embed PRIVATE "${PYTHON_LIBRARIES}") endif() find_package(Threads REQUIRED) target_link_libraries(test_embed PUBLIC ${CMAKE_THREAD_LIBS_INIT}) add_custom_target(cpptest COMMAND $ - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") pybind11_add_module(external_module THIN_LTO external_module.cpp) -set_target_properties(external_module PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) +set_target_properties(external_module PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") +foreach(config ${CMAKE_CONFIGURATION_TYPES}) + string(TOUPPER ${config} config) + set_target_properties(external_module PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${config} "${CMAKE_CURRENT_SOURCE_DIR}") +endforeach() add_dependencies(cpptest external_module) add_dependencies(check cpptest) diff --git a/tests/test_kwargs_and_defaults.py b/tests/test_kwargs_and_defaults.py index 6c72a93689..531a9fdae7 100644 --- a/tests/test_kwargs_and_defaults.py +++ b/tests/test_kwargs_and_defaults.py @@ -2,6 +2,11 @@ import pytest from pybind11_tests import kwargs_and_defaults as m +import platform +import sys + +pypy = platform.python_implementation() == "PyPy" + def test_function_signatures(doc): assert doc(m.kw_func0) == "kw_func0(arg0: int, arg1: int) -> str" @@ -146,6 +151,8 @@ def test_keyword_only_args(msg): """ +@pytest.mark.xfail(pypy and sys.version_info < (3, 0), + reason="PyPy2 doesn't seem to double count") def test_args_refcount(): """Issue/PR #1216 - py::args elements get double-inc_ref()ed when combined with regular arguments""" diff --git a/tests/test_pytypes.py b/tests/test_pytypes.py index 5d2ccf8fd1..4cfc707a32 100644 --- a/tests/test_pytypes.py +++ b/tests/test_pytypes.py @@ -322,7 +322,8 @@ def test_memoryview_from_buffer_empty_shape(): assert view.format == 'B' if sys.version_info.major < 3: # Python 2 behavior is weird, but Python 3 (the future) is fine. - assert bytes(view).startswith(b'