# Run unit tests using CTest and go tests
name: Tests

on:
  push:
    branches:
      - master
      - dev
  pull_request:
    branches:
      - master
      - dev

jobs:
  test:
    runs-on: ${{ matrix.config.os }}
    strategy:
      matrix:
        config:
          - os: ubuntu-latest
            asmnasm: /home/runner/nasm/nasm
            gotests: yes
            cgo_ldflags:
          - os: windows-latest
            asmnasm: C:\Users\runneradmin\nasm\nasm
            gotests: yes
            cgo_ldflags:
          - os: macos-12 # this is intel still
            asmnasm: /Users/runner/nasm/nasm
            gotests: yes
            cgo_ldflags: # -Wl,-no_pie
            # ld on mac is complaining about position dependent code so this would take the errors away, BUT
            # suddenly this causes an error, even though worked last week. Let's accept the warnings rather
            # than let the tests fail because of this.
          # TODO: win32 builds didn't quite work out, complains gcc broken
    steps:
    - uses: lukka/get-cmake@latest
    - uses: vsariola/setup-wabt@v1.0.2
      with:
        version: 1.0.29
    - uses: actions/checkout@v4
    - uses: actions/setup-go@v5 # has to be after checkout, see https://medium.com/@s0k0mata/github-actions-and-go-the-new-cache-feature-in-actions-setup-go-v4-and-what-to-watch-out-for-aeea373ed07d
      with:
        go-version: '>=1.21.0'
    - uses: actions/setup-node@v4
      with:
        node-version: '15'
    - uses: ilammy/setup-nasm@v1.5.1
    - name: Run ctest
      env:
        ASM_NASM: ${{ matrix.config.asmnasm }}
      run: |
        mkdir build
        cd build
        cmake -GNinja ..
        ninja tests/all sointu
        ctest --output-on-failure
    - name: Run go test
      if: ${{ matrix.config.gotests == 'yes' }}
      env:
        CGO_LDFLAGS: ${{ matrix.config.cgo_ldflags }}
      run: |
        go test ./vm ./vm/compiler/bridge ./vm/compiler
