#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

#372 in Testing

Download history 150/week @ 2024-09-06 48/week @ 2024-09-13 26/week @ 2024-09-20 21/week @ 2024-09-27 19/week @ 2024-10-04 21/week @ 2024-10-11 15/week @ 2024-10-18 9/week @ 2024-10-25 36/week @ 2024-11-01 61/week @ 2024-11-08 179/week @ 2024-11-15 79/week @ 2024-11-22 68/week @ 2024-11-29

392 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