To the people running gitlab-runners: Please upgrade to 13.12 to avoid future incompatibilities when we migrate to GitLab 14

Commit 145911da authored by Stefan Schindler's avatar Stefan Schindler
Browse files

Add Coverage with kcov

parent 55e2b533
Pipeline #188 passed with stage
in 2 minutes and 48 seconds
......@@ -10,6 +10,10 @@ image: "rust:latest"
# - redis:latest
# - postgres:latest
variables:
KCOV_DISCARD_CACHE: "false"
APT_CACHE_DIR: apt-cache
# Optional: Install a C compiler, cmake and git into the container.
# You will often need this when you (or any of your dependencies) depends on C code.
#before_script:
......@@ -17,7 +21,26 @@ image: "rust:latest"
#- apt-get install -yqq --no-install-recommends build-essential
# Use cargo to test the project
# And kcov to analyze the coverage:
# https://grauwoelfchen.at/posts/get-test-coverage-for-software-written-in-rust-using-kcov/
test:cargo:
before_script:
- mkdir -pv $APT_CACHE_DIR && apt-get -qq update && apt-get -qqy upgrade
- apt-get -qq -o dir::cache::archives="$APT_CACHE_DIR" install -y
binutils-dev libcurl4-openssl-dev zlib1g-dev libdw-dev libiberty-dev
cmake
- ./ci/build-kcov
- ./kcov/bin/kcov --version
- rustc --version && cargo --version # Print version info for debugging
script:
- rustc --version && cargo --version # Print version info for debugging
- cargo test --all
after_script:
- rm -f target/debug/weighted_random_list-*.d
- ./kcov/bin/kcov --include-path ./src ./target/cov target/debug/weighted_random_list-*
- COVERAGE=$(grep -Po 'covered":.*?[^\\]"' target/cov/index.js* | grep "[0-9]*\.[0-9]" -o)
- echo "Coverage:" $COVERAGE
cache:
untracked: true
paths:
- apt-cache
- kcov
# weighted_random_list
[![CI Status](https://gitlab.com/dns2utf8/weighted_random_list/badges/master/build.svg)](https://gitlab.com/dns2utf8/weighted_random_list)
[![coverage report](https://gitlab.com/dns2utf8/weighted_random_list/badges/master/coverage.svg)](https://gitlab.com/dns2utf8/weighted_random_list/commits/master)
A Vec<T> that allows you to define the weight of each entry and randomly get entries:
......
#!/bin/bash
set -eu
# NOTE:
# if set KCOV_DISCARD_CACHE=true, then it will force installing kcov)
renew="${KCOV_DISCARD_CACHE:-false}"
kcov_dir="kcov"
kcov_bin="${kcov_dir}/bin/kcov"
kcov_url="https://github.com/SimonKagstrom/kcov/archive"
kcov_ver="v34"
if [[ -f "${kcov_bin}" && "${renew}" != "true" ]]; then
echo "kcov already installed in ${kcov_bin}"
else
rm -fr $kcov_dir
mkdir $kcov_dir
cd $kcov_dir
curl -sLO ${kcov_url}/${kcov_ver}.tar.gz
mkdir $kcov_ver
tar zxvf ${kcov_ver}.tar.gz -C $kcov_ver --strip-components=1
cd $kcov_ver
mkdir build
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/
make
make install DESTDIR=../
fi
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment