Crates.io | ensure-cov |
lib.rs | ensure-cov |
version | 0.1.0 |
source | src |
created_at | 2024-09-11 03:53:08.027572 |
updated_at | 2024-09-11 03:53:08.027572 |
description | 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. |
homepage | |
repository | https://github.com/zxch3n/ensure-cov |
max_upload_size | |
id | 1371567 |
size | 18,300 |
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.
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.
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.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);
}