Rust - for Rust

April 11, 2017    rust

While looking for a way to provide code coverage with for Rust, I stumbled upon a solution while reading through Iron.

The solution involves a tool called kcov which is a Linux/OSX code coverage tester for compiled languages.

This tool can be implemented inside a .travis.yml file to push coverage data from a Travis CI  build.

Here is an example .travis.yml file:

sudo: required

language: rust

rust: - stable - beta - nightly

matrix: allow_failures: - rust: nightly

services: - docker

script: - make test-docker-env

cache: apt: true directories: - target/debug/deps - target/debug/build

addons: apt: packages: - libcurl4-openssl-dev - libelf-dev - libdw-dev

after_success: | [ $TRAVIS_RUST_VERSION = stable ] && wget && tar xzf master.tar.gz && mkdir kcov-master/build && cd kcov-master/build && cmake .. && make && make install DESTDIR=../tmp && cd ../.. && ls target/debug && ./kcov-master/tmp/usr/local/bin/kcov –coveralls-id=$TRAVIS_JOB_ID –exclude-pattern=/.cargo target/kcov target/debug/riak-*

Basically all you have to do is run:
./kcov-master/tmp/usr/local/bin/kcov –coveralls-id=$TRAVIS_JOB_ID –exclude-pattern=/.cargo target/kcov target/debug/riak-
Changing “riak-” for your own project, and everything before that is just to compiled kcov inside the Travis CI environment.

This configuration was used for my Riak Rust Client.

Since the above example uses master.tar.gz, I recommend you fork the original repo and use your fork for stability.

Happy Coding!