name: Tests

on: [push, pull_request]

jobs:
  test:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: true
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            toolchain: stable
          - os: macos-latest
            target: x86_64-apple-darwin
            toolchain: stable
          - os: windows-latest
            target: x86_64-pc-windows-gnu
            toolchain: stable
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            toolchain: beta
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            toolchain: 1.36.0 # MSRV
          - os: ubuntu-latest
            deps: sudo apt update ; sudo apt install gcc-multilib
            target: i686-unknown-linux-gnu
            toolchain: nightly

    steps:
      - uses: actions/checkout@v2
      - name: Install toolchain
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          target: ${{ matrix.target }}
          toolchain: ${{ matrix.toolchain }}
          override: true
      - run: ${{ matrix.deps }}
      - name: Test itoap
        run: |
          cargo test --no-default-features
          cargo test --no-default-features --features std
          cargo test --no-default-features --all-features

  test-miri:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Install toolchain
        run: |
          MIRI_NIGHTLY=nightly-$(curl -s https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/miri)
          rustup default "$MIRI_NIGHTLY"
          rustup component add miri
      - name: Test itoap
        run: |
          cargo miri test --no-default-features
          cargo miri test --no-default-features --features std
          cargo miri test --no-default-features --all-features

  test-cross:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: true
      matrix:
        target:
          - aarch64-unknown-linux-gnu
          - armv7-unknown-linux-gnueabihf
          - powerpc-unknown-linux-gnu
          - riscv64gc-unknown-linux-gnu
          - mips-unknown-linux-gnu           # 32-bit big endian
          - mipsel-unknown-linux-musl        # 32-bit little endian
          - mips64-unknown-linux-gnuabi64    # 64-bit big endian
          - mips64el-unknown-linux-gnuabi64  # 64-bit little endian
    steps:
      - uses: actions/checkout@v2
      - name: Install toolchain
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
      - name: Cross test
        uses: actions-rs/cargo@v1
        with:
          command: test
          args: --no-default-features --target ${{ matrix.target }}
          use-cross: true
