GithubHelp home page GithubHelp logo

example-rust's Introduction

Codecov Rust Example

FOSSA Status

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.

Guide

Travis Setup

Add to your .travis.yml file.

NOTE: You should change examplerust in for file in target/debug/examplerust-* ... (under after_success) to match your package name. For example, if your package name is minigrep, then the lines should be changed to for file in target/debug/minigrep-* .... If you are not sure what your package name is, it can also be found in Cargo.toml and it is usually the same name as when you had initialised the project.

language: rust

sudo: required

rust:
  - stable
  - beta
  - nightly

matrix:
  allow_failures:
    - rust: nightly

addons:
  apt:
    packages:
      - libcurl4-openssl-dev
      - libelf-dev
      - libdw-dev
      - cmake
      - gcc
      - binutils-dev
      - libiberty-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 &&
  make install DESTDIR=../../kcov-build &&
  cd ../.. &&
  rm -rf kcov-master &&
  for file in target/debug/examplerust-*; do [ -x "${file}" ] || continue; mkdir -p "target/cov/$(basename $file)"; ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file"; done &&
  bash <(curl -s https://codecov.io/bash) &&
  echo "Uploaded code coverage"

This will automatically run each executable and store the results in a different directory. Codecov will automatically find the cobertura.xml files that kcov generates and combine the results.

Other CI services

  • Adjust the materials in the above example as necessary for your CI.
  • Add CODECOV_TOKEN= to your CI's environment variables. (Don't store the raw token in your repo.)
  • Run bash <(curl -s https://codecov.io/bash) after tests complete.

Produce Coverage Reports

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>

<PROJECT-NAME> and <hash> are the appropriate project name and hash for your executable.

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 like <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.

Note that setting the environment variable RUSTFLAGS="-C link-dead-code" during tests build may improve coverage accuracy by preventing dead-code elimination. Do not set this variable when creating release builds since it will increase binary size.

After you've run the tests and created a cobertura.xml report, you can use [the Codecov global uploader][4] to push that report to Codecov. See below for further details.

Installing 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 computer.

Caveats

Private Repos

Add to your .travis.yml file.

after_success:
  - bash <(curl -s https://codecov.io/bash) -t uuid-repo-token

kcov Version

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 in the .travis.yml file.

  1. More documentation at https://docs.codecov.io
  2. Configure codecov through the codecov.yml https://docs.codecov.io/docs/codecov-yaml

We are happy to help if you have any questions. Please contact email our Support at [email protected]

License

FOSSA Status

example-rust's People

Contributors

chrisjwelly avatar fossabot avatar lesnyrumcajs avatar phsym avatar serayuzgur avatar sunjay avatar thebiggerguy avatar thedan64 avatar thomasrockhu avatar tomped avatar xfbs avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.