name: Integration test

on: [push, pull_request]

jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        python-version: [ 2.7, 3.5, 3.6, 3.7, 3.8, 3.9, "3.10" ]
        cffi: [ yes, no ]
        os: [ ubuntu-latest ]
        include:
          - python-version: 2.7
            cffi: no
            os: macos-latest
          - python-version: 2.7
            cffi: yes
            os: macos-latest
          - python-version: "3.10"
            cffi: yes
            os: macos-latest
          - python-version: 2.7
            cffi: no
            os: windows-latest
          - python-version: 2.7
            cffi: yes
            os: windows-latest
          - python-version: "3.10"
            cffi: no
            os: windows-latest
          - python-version: "3.10"
            cffi: yes
            os: windows-latest
          - python-version: pypy2
            cffi: no
            os: ubuntu-latest
          - python-version: pypy3
            cffi: no
            os: ubuntu-latest
    env:
      CFLAGS: "-Wconversion"

    steps:
    - uses: actions/checkout@v2

    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}

    - name: Display Python version
      run: python -c "from __future__ import print_function; import sys; print(sys.version)"

    - name: Install CFFI
      if: matrix.cffi == 'yes'
      run: pip install cffi

    - name: Install MSVC
      if: matrix.os == 'windows-latest' && matrix.python-version == '2.7'
      uses: ilammy/msvc-dev-cmd@f456b805b3f63911738cb71d4f255e4e129c7e7a

    - name: Prepare environmental variables
      if: matrix.os == 'windows-latest' && matrix.python-version == '2.7'
      shell: bash
      run: |
        echo "DISTUTILS_USE_SDK=1" >> $GITHUB_ENV
        echo "MSSdk=1" >> $GITHUB_ENV

    - name: Install dependencies
      run: |
        pip install pycryptodome-test-vectors

    - name: Test
      run: |
        python -bb setup.py test

  mypy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python 3.10
      uses: actions/setup-python@v2
      with:
        python-version: "3.10"
    - name: Install dependencies
      run: |
        pip install mypy pycryptodome-test-vectors
    - name: Test
      run: |
        mypy lib/

  test_c:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Test
      run: |
        cd src/test
        make

  test_c_i386:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Install dependencies
      run: |
        sudo apt-get update
        sudo apt-get install libc6-dev-i386
    - name: Test
      run: |
        cd src/test
        CFLAGS="-m32" UNDEFS="-UHAVE_UINT128" make

  test_c_sse2:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Test
      run: |
        cd src/test
        CPPFLAGS="-DHAVE_X86INTRIN_H" make

