name: Tests

on:
  push:
    branches: [ "**" ]
  pull_request:
    branches: [ "**" ]

jobs:
  macos-tests:
    runs-on: macos-latest

    steps:
    - uses: actions/checkout@v3

    - name: Setup SDL2
      uses: ./.github/actions/setup-sdl2-macos

    - name: Download & install premake
      working-directory: RecastDemo
      run: |
        curl -L -o premake.tar.gz https://github.com/premake/premake-core/releases/download/v5.0.0-beta8/premake-5.0.0-beta8-macosx.tar.gz
        tar -xzf premake.tar.gz
        rm premake.tar.gz
        chmod 777 ./premake5

    - name: Run premake
      working-directory: RecastDemo
      run: ./premake5 xcode4

    - name: Build Unit Tests With Xcode
      working-directory: RecastDemo/Build/xcode4/
      run: xcodebuild -scheme Tests -configuration Debug -project Tests.xcodeproj build

    - name: Run unit tests
      working-directory: RecastDemo/Bin
      run: ./Tests --verbosity high --success
  
  linux-tests:
    runs-on: ubuntu-24.04

    steps:
    - uses: actions/checkout@v3

    - name: Setup SDL2
      uses: ./.github/actions/setup-sdl2-linux

    - name: Install clang
      run: |
        sudo apt-get install -y clang
        clang --version

    - name: Download & Install premake
      working-directory: RecastDemo
      run: |
        curl -L -o premake.tar.gz https://github.com/premake/premake-core/releases/download/v5.0.0-beta8/premake-5.0.0-beta8-linux.tar.gz
        tar -xzf premake.tar.gz
        rm premake.tar.gz
        chmod 777 ./premake5
    
    - name: Run premake
      working-directory: RecastDemo
      run: ./premake5 --cc=clang gmake

    - name: Build
      working-directory: RecastDemo/Build/gmake
      run: make config=debug verbose=true
    
    - name: Run Tests
      working-directory: RecastDemo/Bin
      run: ./Tests --verbosity high --success
  
  windows-tests:
    runs-on: windows-2022

    steps:
    - uses: actions/checkout@v3

    - name: Add msbuild to PATH
      uses: microsoft/setup-msbuild@v1.1

    - name: Setup SDL2
      uses: ./.github/actions/setup-sdl2-windows

    - name: Download and Install Premake
      working-directory: RecastDemo
      shell: pwsh
      run: |
        (new-object System.Net.WebClient).DownloadFile("https://github.com/premake/premake-core/releases/download/v5.0.0-beta8/premake-5.0.0-beta8-windows.zip","${{github.workspace}}/RecastDemo/premake.zip")
        tar -xf premake.zip
        del premake.zip

    - name: Run Premake
      working-directory: RecastDemo
      run: ./premake5.exe vs2022

    - name: Build
      working-directory: RecastDemo/Build/vs2022
      run: msbuild Tests.vcxproj -property:Configuration=Debug -property:Platform=x64

    - name: Run Tests
      working-directory: RecastDemo/Bin/
      run: ./Tests.exe --verbosity high --success