---
language: rust
dist: trusty
sudo: required

matrix:
  include:
    - rust: 1.34.0
    # cfg(doctest) is experimental in 1.39 but ignored with 1.34.0, and that snuck in when 1.39.0 wasn't tested
    - rust: 1.39.0
    - rust: stable
    - rust: beta
    - rust: nightly
      addons:
        apt:
          packages:
            # cargo-tarpaulin needs this
            - libssl-dev
      install:
        # For test coverage. In install step so that it can use cache.
        - cargo tarpaulin --version || RUSTFLAGS="--cfg procmacro2_semver_exempt" cargo install --force cargo-tarpaulin
        - cargo +nightly install cargo-fuzz

    # no_std
    - rust: stable
      env: TARGET="--target thumbv6m-none-eabi" FEATURES="--no-default-features --features alloc"
      install:
        - rustup target add thumbv6m-none-eabi

cache: cargo

env:
  # prevent cargo fuzz list from printing with color
  - TERM=dumb

script:
  - cargo build --verbose $TARGET --no-default-features 
  - cargo build --verbose $TARGET $FEATURES
  - 'if [[ -z "$TARGET" ]]; then cargo test --verbose; fi'
  - 'if [[ -z "$TARGET" ]]; then cargo doc --verbose; fi'
  - 'if [[ "$TRAVIS_RUST_VERSION" = nightly ]]; then cargo bench --no-run; fi'
  # run for just a second to confirm that it can build and run ok
  - 'if [[ "$TRAVIS_RUST_VERSION" = nightly ]]; then cargo fuzz list | xargs -L 1 -I FUZZER cargo fuzz run FUZZER -- -max_total_time=1; fi'

after_success: |
  if [[ "$TRAVIS_RUST_VERSION" = nightly ]]; then
    # Calculate test coverage
    cargo tarpaulin --out Xml
    bash <(curl -s https://codecov.io/bash)
  fi
