name: Test

on:
  push:
    branches: [main, master]
  pull_request:
    branches: [main, master]

env:
  CARGO_TERM_COLOR: always

jobs:
  test:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]

    steps:
      - uses: actions/checkout@v4

      - name: Install Java 21
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: '21'

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable

      - name: Cache Rust
        uses: Swatinem/rust-cache@v2

      - name: Cache Ghidra
        uses: actions/cache@v4
        with:
          path: |
            ~/.local/share/ghidra-cli
            ~/Library/Application Support/ghidra-cli
            ~/AppData/Local/ghidra-cli
          key: ghidra-${{ matrix.os }}-v2

      - name: Build
        run: cargo build --verbose

      - name: Build test fixture
        run: rustc --edition 2021 -o tests/fixtures/sample_binary tests/fixtures/sample_binary.rs

      - name: Setup Ghidra
        run: cargo run -- setup --force

      - name: Run unit tests
        run: cargo test --lib --verbose

      - name: Run integration tests
        run: cargo test --test '*' --verbose
        env:
          RUST_LOG: info
