name: Tests

on:
  push:
    branches:
    - main
    - develop
  pull_request:
    branches:
    - main
    - develop

  workflow_dispatch:

jobs:
  build_and_test:
    name: Test library with backend ${{ matrix.name }}, running on ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false # show all errors for each platform (vs. cancel jobs on error)
      matrix:
        include:
        - os: ubuntu-latest
          name: "Eigen"
          backend: "-DRTNEURAL_EIGEN=ON"
#        - os: ubuntu-latest
#          name: "Eigen - AVX"
#          backend: "-DRTNEURAL_EIGEN=ON -DRTNEURAL_USE_AVX=ON"
        - os: ubuntu-latest
          name: "xsimd"
          backend: "-DRTNEURAL_XSIMD=ON"
#        - os: ubuntu-latest
#          name: "xsimd - AVX"
#          backend: "-DRTNEURAL_XSIMD=ON -DRTNEURAL_USE_AVX=ON"
        - os: ubuntu-latest
          name: "STL"
          backend: "-DRTNEURAL_STL=ON"
        - os: windows-latest
          name: "Eigen"
          backend: "-DRTNEURAL_EIGEN=ON"
        - os: windows-latest
          name: "Eigen - AVX"
          backend: "-DRTNEURAL_EIGEN=ON -DRTNEURAL_USE_AVX=ON"
        - os: windows-latest
          name: "xsimd"
          backend: "-DRTNEURAL_XSIMD=ON"
        - os: windows-latest
          name: "xsimd - AVX"
          backend: "-DRTNEURAL_XSIMD=ON -DRTNEURAL_USE_AVX=ON"
        - os: windows-latest
          name: "STL"
          backend: "-DRTNEURAL_STL=ON"
        - os: macos-latest
          name: "Eigen"
          backend: "-DRTNEURAL_EIGEN=ON"
#        - os: macos-latest
#          name: "Eigen - AVX"
#          backend: "-DRTNEURAL_EIGEN=ON -DRTNEURAL_USE_AVX=ON"
        - os: macos-latest
          name: "xsimd"
          backend: "-DRTNEURAL_XSIMD=ON"
#        - os: macos-latest
#          name: "xsimd - AVX"
#          backend: "-DRTNEURAL_XSIMD=ON -DRTNEURAL_USE_AVX=ON"
        - os: macos-latest
          name: "STL"
          backend: "-DRTNEURAL_STL=ON"
    
    steps:
    - name: Get latest CMake
      uses: lukka/get-cmake@latest

    - name: Checkout code
      uses: actions/checkout@v2
      with:
        submodules: true

    - name: Configure
      env:
        BACKEND_ARG: ${{ matrix.backend }}
      shell: bash
      run: cmake -Bbuild -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=ON $BACKEND_ARG

    - name: Build
      shell: bash
      run: cmake --build build --config Release --parallel

    - name: Test
      shell: bash
      run: ctest -C Release --test-dir build --parallel --output-on-failure
