GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'
EXCLUDE="/.cargo,/usr/lib,/usr/include,rdkafka-sys"
TARGET="target/cov"
UNIT_TESTS="target/debug/rdkafka-"
INTEGRATION_TESTS="target/debug/test_"
echo -e "${GREEN}*** Clean previous coverage results and executables ***${NC}"
rm -rf "$TARGET"
rm "$UNIT_TESTS"*
rm "$INTEGRATION_TESTS"*
echo -e "${GREEN}*** Rebuilding tests ***${NC}"
cargo test --no-run
echo -e "${GREEN}*** Run coverage on unit tests ***${NC}"
kcov --exclude-pattern="$EXCLUDE" --verify "$TARGET" "$UNIT_TESTS"*
echo -e "${GREEN}*** Run coverage on integration tests ***${NC}"
for test_file in `ls "$INTEGRATION_TESTS"*`
do
echo -e "${GREEN}Executing "$test_file"${NC}"
kcov --exclude-pattern="$EXCLUDE" --verify "$TARGET" "$test_file"
if [ "$?" != "0" ]; then
echo -e "${RED}*** Failure during integration converage ***${NC}"
exit 1
fi
done
echo -e "${GREEN}*** Coverage complete ***${NC}"