name: tests

on: [push, pull_request]

jobs:
  cargo_tests:
    name: ${{ matrix.target.name }} ${{ matrix.channel }}
    runs-on: ${{ matrix.target.os }}
    strategy:
      fail-fast: false
      matrix:
        target: [
          { "os": "ubuntu-latest",  "toolchain": "x86_64-unknown-linux-gnu", "name": "Linux GNU" },
          { "os": "macOS-latest",   "toolchain": "aarch64-apple-darwin",     "name": "macOS" },
          { "os": "windows-latest", "toolchain": "x86_64-pc-windows-msvc",   "name": "Windows MSVC" },
          { "os": "windows-latest", "toolchain": "x86_64-pc-windows-gnu",    "name": "Windows GNU" }
        ]
        channel: [stable, beta, nightly]

    steps:
    - uses: actions/checkout@v1
    - uses: actions-rs/toolchain@v1
      with:
        toolchain: ${{ format('{0}-{1}', matrix.channel, matrix.target.toolchain) }}
        profile: minimal
        override: true
    - name: test lib
      run: cargo test
    - name: test lib with --release
      run: cargo test --release
    - name: test bin
      run: cargo test
      working-directory: ./bao_bin
    - name: test bin --no-default-features
      run: cargo test --no-default-features
      working-directory: ./bao_bin

  cargo_test_benches:
    name: test benches
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
    steps:
    - uses: actions/checkout@v1
    - uses: actions-rs/toolchain@v1
      with:
        toolchain: nightly
        profile: minimal
        override: true
    - name: test benches
      run: cargo test --benches