#coverage #ci

ensure-cov

A simple Rust crate designed to help ensure test coverage in your projects by providing functions to track and assert code coverage during test execution

1 unstable release

0.1.0 Sep 11, 2024

#358 in Testing

Download history 169/week @ 2024-09-09 36/week @ 2024-09-16 23/week @ 2024-09-23 23/week @ 2024-09-30 20/week @ 2024-10-07 20/week @ 2024-10-14 14/week @ 2024-10-21 19/week @ 2024-10-28 34/week @ 2024-11-04 97/week @ 2024-11-11

165 downloads per month
Used in 3 crates (2 directly)

MIT/Apache

7KB
67 lines

ensure-cov

ensure-cov is a simple Rust crate designed to help ensure test coverage in your projects. It provides a set of functions to track and assert code coverage during test execution.

Features

  • Track code coverage for specific named sections
  • Assert that certain code paths have been covered
  • Check the number of times a specific section has been covered
  • Clear coverage data

Usage

The crate's functionality is enabled when the crate is compiled in test or debug mode. In release builds or when the disable feature is enabled, all functions become no-ops, ensuring zero overhead in production.

API

When enabled, the crate provides the following functions:

  • notify_cov(name: &str): Increment the coverage count for a named section.
  • assert_cov(name: &str): Assert that a named section has been covered at least once.
  • assert_cov_at_least(name: &str, expected: usize): Assert that a named section has been covered at least expected number of times.
  • get_cov_for(name: &str) -> usize: Get the current coverage count for a named section.
  • clear_cov(): Clear all coverage data.

Example

use ensure_cov::*;

#[test]
fn test_coverage() {
    notify_cov("section_a");
    notify_cov("section_b");
    notify_cov("section_b");

    assert_cov("section_a");
    assert_cov_at_least("section_b", 2);

    assert_eq!(get_cov_for("section_a"), 1);
    assert_eq!(get_cov_for("section_b"), 2);

    clear_cov();
    assert_eq!(get_cov_for("section_a"), 0);
}

No runtime deps

Features