#!/bin/sh

export CARGO_TARGET_DIR=target/kcov

cargo_kcov_args="$*"

# coverage must be run on each crate individually because of:
#   https://github.com/kennytm/cargo-kcov/issues/39

run_kcov()
{
    path="$1"
    shift
    features="$*"
    cargo kcov \
          --verbose \
          $cargo_kcov_args \
          --output="target/kcov/cov/$path" \
          --manifest-path="$path/Cargo.toml" \
          $features \
          -- \
          --verify \
          --exclude-pattern=$HOME/.cargo,$HOME/.rustup,/usr/include,/usr/src/debug
}

mkdir -p target/kcov/cov/.
run_kcov . $features
kcov --merge target/kcov/cov target/kcov/cov/.
