rust-covfix

Build Status Build status codecov Version docs GitHub Release Date License: MIT PRs Welcome

Rustc is known to report an incorrect coverage for some lines (https://stackoverflow.com/questions/32521800/why-does-kcov-calculate-incorrect-code-coverage-statistics-for-rust-programs). rust-covfix will read coverage from the file generated by grcov), fix it, then outputs the correct coverage.

Though only lcov format is supprted at current, Another formats is going to be supported in future releases.

Features

Optional features

Optional features are available with cargo's --features option. You can specify the features like:

console $ cargo install --no-default-features --features "cli lcov"

|Feature name|Description|Default?| |:--:|--|:--:| |cli|Command Line Interface. This feature is required to build rust-covfix executable.|yes| |lcov|Make LcovParser available|yes| |noinline|Avoid adding #cfg[inline] attribute on function.|no| |backtrace|Dump backtrace information on every time the error has occured.|no|

Install

Download the latest release from GitHub Release Page.

You can also install via cargo command.

console $ cargo install rust-covfix

Usage

```console $ rust-covfix --help Usage: rust-covfix [OPTIONS] FILE

Rust coverage fixer

Positional arguments: file coverage file

Optional arguments: -h,--help Show this help message and exit -V,--version display version -v,--verbose verbose output -n,--no-fix do not fix coverage -o,--output FILE output file name (default: stdout) --root DIR project root directory --rules STR[,STR..] use specified rules to fix coverages. Valid names are [close, test, loop, derive] ```

How is the incorrect line coverage detected

rust_covfix fixes the coverage information using some rules. You can pass --rules option to specify which rules are used to fix coverages.

Rules

close

closing brackets, line of else block will be ignored.

rust if a > 0 { b = a } else { // <-- marked as "not executable" b = -a }; // <-- marked as "not executable"

test

module block named test or tests which has attribute cfg(test) will be ignored

```rust

[cfg(test)]

mod tests { // <-- removed from coverage fn util() { ... } // <-- removed from coverage

#[test]
fn test_hoge() { ... }  // <-- removed from coverage

} ```

loop

Fix rust internal bugs that loop branches are not correctly passed.

rust for i in 0..10 { // <-- fix branch coverage information println!("{}", i); }

derive

structs with derive(...) attribute will be ignored

```rust

[derive(Clone, Debug)] // <-- removed from coverage

struct Point { // <-- removed from coverage x: f64, // <-- removed from coverage y: f64 // <-- removed from coverage } // <-- removed from coverage ```

comment

ignore coverage based on comment marker

```rust fn main() { let a = 1 + 2; // cov:ignore-line

// cov:begin-ignore-branch
println!("Hello");
println!("world!");
// cov:end-ignore-branch

// cov: begin-ignore-line
if a > 2 {
    println!("a is large!");
} else if a == 0 {
    println!("a is small!");
}
// cov: end-ignore-line

// cov:begin-ignore
println!("a = {}", a);
// cov:end-ignore

println!("finish."); // cov:ignore-branch

return (); // cov:ignore

} ```

Roadmap

Author

👤 Kogia-sima

🤝 Contributing

Contributions, issues and feature requests are welcome!

Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!

📝 License

Copyright © 2019 Kogia-sima.

This project is MIT licensed.


This README was generated with ❤️ by readme-md-generator