#!/bin/sh -e

# Script prerequisites:
#   Rust toolchain
#   lcov package (for genhtml)
#   cargo install cargo-llvm-cov

COVERAGE_DIR=target/coverage

if [ "$1" != "--stable" ]; then
    NIGHTLY="+nightly";
    echo "NOTE: Using nightly compiler. Run with --stable to use your default set in rustup."
else
    :
fi

mkdir -p $COVERAGE_DIR
# shellcheck disable=SC2086
cargo ${NIGHTLY} llvm-cov --doctests --lcov --all-features --output-path $COVERAGE_DIR/lcov.info
genhtml $COVERAGE_DIR/lcov.info -o $COVERAGE_DIR/html
echo Coverage written to $COVERAGE_DIR/html
