This repository serves as an example of how to use the Codecov global uploader with Rust.
As of July 2, 2016, there is no option to make rustdoc generate a runnable test executable. That means that documentation tests will not show in your coverage data. If you discover a way to run the doctest executable with kcov, please open an Issue and we will add that to these instructions.
Run your tests with kcov in order to create the necessary coverage reports. For example:
kcov --exclude-pattern=/.cargo,/usr/lib --verify target/cov target/debug/<PROJECT-NAME>-<hash>
<hash> are the appropriate project name and hash for
The hash at the end may change if cargo generates different test executables with the same name. If you are building your code differently or without cargo, change the last two arguments to kcov to respectively represent where you want the coverage to be stored and which executable to run.
Attempting to run
kcov with an executable argument ending in a wildcard
<PROJECT-NAME>-* may result in incorrect coverage results as only a
single test executable will run. For best results, run the kcov command
for each test executable and store the results in separate directories.
Codecov will automatically find and upload the cobertura.xml files and
merge the coverage for you.
After you've run the tests and created a cobertura.xml report, you can use the Codecov global uploader to push that report to Codecov. See below for further details.
kcov is largely dependent on your operating system. It is
demonstrated to work on Linux systems but may not be fully compatible with
Windows or OS X. Please lookup the appropriate installation instructions.
The Travis CI example below demonstrates installing
kcov on a Linux
The version of
kcov that is distributed with your package manager may not
work with Rust binaries. You usually need to manually build the latest
master branch and run kcov from there. All of this is taken care of for you
.travis.yml file below.
Adjust the following example
.travis.yml file to test with the versions
of Rust you desire.
language: rust rust: - 1.9.0 before_install: - sudo apt-get update addons: apt: packages: - libcurl4-openssl-dev - libelf-dev - libdw-dev - cmake - gcc - binutils-dev after_success: | wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz && tar xzf master.tar.gz && cd kcov-master && mkdir build && cd build && cmake .. && make && sudo make install && cd ../.. && rm -rf kcov-master && for file in target/debug/<PROJECT-NAME>-*; do mkdir -p "target/cov/$(basename $file)"; kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file"; done && bash <(curl -s https://codecov.io/bash) && echo "Uploaded code coverage"
Codecov is integrated by the following line in
bash <(curl -s https://codecov.io/bash)
This will automatically run each executable and store the results in a
different directory. Codecov will automatically find the
kcov generates and combine the results.
Add to your
env: global: - CODECOV_TOKEN=:uuid-repo-token
Other CI services
- Adjust the materials in the above example as necessary for your CI.
CODECOV_TOKEN=<your repo token>to your CI's environment variables. (Don't store the raw token in your repo.)
bash <(curl -s https://codecov.io/bash)after tests complete.
Visit the global uploader's repo to view its source and learn more about the script.