trigger:
  - main

strategy:
  matrix:
    linux-stable:
      image: ubuntu-18.04
      style: 'unflagged'
    linux-minimal:
      image: ubuntu-18.04
      style: 'minimal'
    linux-extra:
      image: ubuntu-18.04
      style: 'extra'
    linux-wasm:
      image: ubuntu-18.04
      style: 'wasm'
    macos-stable:
      image: macos-10.14
      style: 'unflagged'
    windows-stable:
      image: windows-2019
      style: 'unflagged'
    fmt:
      image: ubuntu-18.04
      style: 'fmt'

pool:
  vmImage: $(image)

steps:
  - bash: |
      set -e
      if [ -e /etc/debian_version ]
      then
        sudo apt-get -y install libxcb-composite0-dev libx11-dev
      fi
      if [ "$(uname)" == "Darwin" ]; then
        curl https://sh.rustup.rs -sSf | sh -s -- -y --no-modify-path --default-toolchain "stable"
        echo "Installing clippy"
        rustup component add clippy --toolchain stable-x86_64-apple-darwin
        export PATH=$HOME/.cargo/bin:$PATH
      fi
  #     rustup update
  #     rustc -Vv
  #     echo "##vso[task.prependpath]$HOME/.cargo/bin"
  #     rustup component add rustfmt
    displayName: Install Rust
  - bash: RUSTFLAGS="-D warnings" cargo test --all
    condition: eq(variables['style'], 'unflagged')
    displayName: Run tests
  - bash: RUSTFLAGS="-D warnings" cargo clippy --all -- -D clippy::unwrap_used -A clippy::needless_collect
    condition: eq(variables['style'], 'unflagged')
    displayName: Check clippy lints
  - bash: cd samples/wasm && npm install wasm-pack && node ./node_modules/wasm-pack/run.js build
    condition: eq(variables['style'], 'wasm')
    displayName: Wasm build
  - bash: RUSTFLAGS="-D warnings" cargo test --all --no-default-features --features=rustyline-support
    condition: eq(variables['style'], 'minimal')
    displayName: Run tests
  - bash: RUSTFLAGS="-D warnings" cargo test --all --features=extra
    condition: eq(variables['style'], 'extra')
    displayName: Run tests
  - bash: cargo fmt --all -- --check
    condition: eq(variables['style'], 'fmt')
    displayName: Lint
