set -eu
output_dir="$(pwd)/target/coverage"
target_dir="$(pwd)/target/debug"
if [ -f "${output_dir}/index.json" ]; then
rm "${output_dir}/index.json"
fi
if [ -n "${2:-}" ]; then
kcov_cmd="${2}"
elif [ ! -z "${KCOV_PATH:-}" ]; then
kcov_cmd="${KCOV_PATH}"
else
kcov_dir="$(dirname $(readlink -f "${0}"))/kcov"
kcov_cmd="${kcov_dir}/bin/kcov"
fi
echo "$kcov_cmd"
prefix="${1}"
for file in $(ls $target_dir/$prefix* | grep -v '\.d$'); do
echo $file
$kcov_cmd --verify --include-path=$(pwd)/src \
"$output_dir" "$file"
grep -E "$(basename $file)" "$output_dir"/index.json | \
grep -oE 'covered":"([0-9]*\.[0-9]*|[0-9]*)"' | \
grep -oE '[0-9]*\.[0-9]*|[0-9]*'
done