name: test

on:
  push:

env:
  CARGO_TERM_COLOR: always
  RUST_BACKTRACE: full

jobs:
  test:
    name: Build & test
    strategy:
      fail-fast: false
      matrix:
        os:
          - ubuntu-latest
          - macos-latest
          - windows-latest
        rust:
          - stable
          - beta
          - nightly

    runs-on: ${{ matrix.os }}

    steps:
      - name: checkout
        uses: actions/checkout@v2

      - name: Install Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: ${{ matrix.rust }}
          default: true
          profile: minimal

      - name: Restore cache
        uses: Swatinem/rust-cache@v1

      - name: Build & test
        env:
          RUST_VERSION: ${{ matrix.rust }}
          OS: ${{ matrix.os }}
          RUSTFLAGS: -D warnings
        run: cargo test --all-features

  rustfmt:
    name: Check formatting
    runs-on: ubuntu-latest
    steps:
      - name: checkout
        uses: actions/checkout@v2

      - name: Install Rust
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          default: true
          components: rustfmt

      - run: cargo fmt --all -- --check

  links:
    name: Check documentation links
    runs-on: ubuntu-latest
    steps:
      - name: checkout
        uses: actions/checkout@v2

      - name: Install Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          default: true

      - name: Restore cache
        uses: Swatinem/rust-cache@v1

      - name: Check links
        run: cargo rustdoc --all-features -- -D warnings

  clippy:
    name: Clippy lints
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Install Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          profile: minimal
          default: true
          components: clippy

      - name: Restore cache
        uses: Swatinem/rust-cache@v1

      - name: Run clippy linter
        run: cargo clippy --all --all-features --tests -- -D clippy::all -D warnings

#  miri:
#    name: Miri checks
#    runs-on: ubuntu-latest
#    steps:
#      - name: Checkout repository
#        uses: actions/checkout@v2
#
#      - name: Install Rust
#        uses: actions-rs/toolchain@v1
#        with:
#          toolchain: nightly
#          profile: minimal
#          default: true
#          components: "miri"
#
#      - name: Restore cache
#        uses: Swatinem/rust-cache@v1
#
#      - name: Run miri
#        env:
#          PROPTEST_CASES: "10"
#          MIRIFLAGS: "-Zmiri-disable-isolation"
#        run: cargo miri test --all-features
