Skip to content

Instantly share code, notes, and snippets.

@colin-kiegel
Last active November 28, 2015 01:44
Show Gist options
  • Save colin-kiegel/e3a1fea04cd3ad8ed06d to your computer and use it in GitHub Desktop.
Save colin-kiegel/e3a1fea04cd3ad8ed06d to your computer and use it in GitHub Desktop.
cargo-kcov
#!/bin/bash
# original source https://users.rust-lang.org/t/tutorial-how-to-collect-test-coverages-for-rust-project/650
# modified version https://gist.github.com/colin-kiegel/e3a1fea04cd3ad8ed06d
PKGID="$(cargo pkgid)"
[ -z "$PKGID" ] && exit 1
ORIGIN="${PKGID%#*}"
ORIGIN="${ORIGIN:7}"
PKGNAME="${ORIGIN##*/}"
PKGNAMEVER="${PKGID#*#}"
echo "cargo pkgid: $PKGID"
echo " -> origin: $ORIGIN"
echo " -> name: $PKGNAME"
echo " -> version: $PKGNAMEVER"
shift
cargo test --no-run || exit $?
EXE=($ORIGIN/target/debug/$PKGNAME-*)
if [ ${#EXE[@]} -ne 1 ]; then
echo 'Non-unique test file, retrying...' >2
rm -f ${EXE[@]}
cargo test --no-run || exit $?
fi
rm -rf $ORIGIN/target/cov
kcov --verify $ORIGIN/target/cov $ORIGIN/target/debug/$PKGNAME-* "$@"
@colin-kiegel
Copy link
Author

  • download to /usr/local/bin
  • make it executable via chmod +x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment