name: CLI tests

on:
  workflow_call:
    inputs:
      all-platforms:
        required: false
        default: true
        type: boolean

jobs:
  test-cli:
    strategy:
      matrix:
        platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-24.04", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-24.04"]') }}
    runs-on: ${{ matrix.platform }}
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: true
          fetch-depth: 0
      - name: Prepare build environment
        uses: ./.github/actions/prepare-build-env
      - name: Test lfc bash scripts (Linux or macOS only)
        run: |
          .github/scripts/test-lfc.sh
          ./gradlew assemble
          ./build/install/lf-cli/bin/lfc --version
          ./build/install/lf-cli/bin/lfc test/C/src/Minimal.lf
        if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }}
      - name: Test lff bash scripts (Linux or macOS only)
        run: |
          .github/scripts/test-lff.sh
          ./gradlew assemble
          ./build/install/lf-cli/bin/lff --version
          ./build/install/lf-cli/bin/lff test/C/src/Minimal.lf
        if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }}
      - name: Test lfd bash scripts (Linux or macOS only)
        run: |
          .github/scripts/test-lfd.sh
          ./gradlew assemble
          ./build/install/lf-cli/bin/lfd --version
          ./build/install/lf-cli/bin/lfd test/C/src/Minimal.lf
        if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }}
      - name: Test lfc PowerShell script (Windows only)
        run: |
          bin/lfc-dev.ps1 --version
          bin/lfc-dev.ps1 test/C/src/Minimal.lf
          ./gradlew assemble
          ./build/install/lf-cli/bin/lfc.bat --version
          ./build/install/lf-cli/bin/lfc.bat test/C/src/Minimal.lf
        if: ${{ runner.os == 'Windows' }}
      - name: Test lff PowerShell script (Windows only)
        run: |
          bin/lff-dev.ps1 --version
          bin/lff-dev.ps1 test/C/src/Minimal.lf
          ./gradlew assemble
          ./build/install/lf-cli/bin/lff.bat --version
          ./build/install/lf-cli/bin/lff.bat test/C/src/Minimal.lf
        if: ${{ runner.os == 'Windows' }}
      - name: Test lfd PowerShell script (Windows only)
        run: |
          bin/lfd-dev.ps1 --version
          bin/lfd-dev.ps1 test/C/src/Minimal.lf
          ./gradlew assemble
          ./build/install/lf-cli/bin/lfd.bat --version
          ./build/install/lf-cli/bin/lfd.bat test/C/src/Minimal.lf
        if: ${{ runner.os == 'Windows' }}
