task:
  name: FreeBSD $FREEBSD_VERSION ($TOOLCHAIN)

  freebsd_instance:
    cpu: 1
    image_family: $FREEBSD_IMAGE

  matrix:
    - env:
        FREEBSD_VERSION: 12.1
        FREEBSD_IMAGE: freebsd-12-1
    - env:
        FREEBSD_VERSION: 12.1 STABLE
        FREEBSD_IMAGE: freebsd-12-1-snap
    # - env:
    #     FREEBSD_VERSION: 13.0
    #     FREEBSD_IMAGE: freebsd-13-0-snap

  matrix:
    - env:
        TOOLCHAIN: stable
    - env:
        TOOLCHAIN: beta
    - env:
        TOOLCHAIN: nightly

  env:
    CODECOV_TOKEN: ENCRYPTED[5179440ab976edd14e226acd747428907dfae313e6a42dd9dfe4863589f624c011527317e9141b73398f09fe0b128701]

  install_script:
    - pkg install -y curl kcov bash
    - curl -sSf https://sh.rustup.rs -o rustup.sh
    - sh rustup.sh -y --profile default --default-toolchain $TOOLCHAIN
  build_script:
    - . $HOME/.cargo/env
    - cargo build
  test_script:
    - . $HOME/.cargo/env
    - cargo test
    - |
      mkdir -p coverage-build
      for f in target/debug/deps/*; do
        if [ -x "$f" ]; then
          kcov --exclude-pattern=/.cargo,/.rustup,/usr/lib --verify coverage-build/ "$f"
        fi
      done
  coverage_collect_upload_script:
    - kcov --merge coverage-merged/ coverage-build/
    - OS="$FREEBSD_IMAGE" bash <(curl -s https://codecov.io/bash) -e OS,TOOLCHAIN -n "$FREEBSD_IMAGE-$TOOLCHAIN" -Z -f coverage-merged/kcov-merged/cobertura.xml
