Skip to main content

CoverageResult

Struct CoverageResult 

Source
pub struct CoverageResult {
Show 13 fields pub name: String, pub version: String, pub line_pct: f64, pub function_pct: f64, pub region_pct: f64, pub branch_pct: Option<f64>, pub total_lines: u64, pub covered_lines: u64, pub total_functions: u64, pub covered_functions: u64, pub total_regions: u64, pub covered_regions: u64, pub files: Vec<FileCoverage>,
}
Expand description

Result of a coverage run.

Top-level percentages and counts are always populated. The files vector is populated only when the run was configured with CoverageRun::per_file.

§Example

use dev_coverage::CoverageResult;

let r = CoverageResult {
    name: "my-crate".into(),
    version: "0.1.0".into(),
    line_pct: 87.5,
    function_pct: 90.0,
    region_pct: 82.0,
    branch_pct: None,
    total_lines: 200,
    covered_lines: 175,
    total_functions: 50,
    covered_functions: 45,
    total_regions: 100,
    covered_regions: 82,
    files: Vec::new(),
};
assert!(r.line_pct > 80.0);

Fields§

§name: String

Crate or subject name (descriptive; matches the Report subject).

§version: String

Subject version (descriptive; matches the Report subject_version).

§line_pct: f64

Percentage of executable lines exercised by tests. 0.0..=100.0.

§function_pct: f64

Percentage of functions called by tests. 0.0..=100.0.

§region_pct: f64

Percentage of regions (branch points) exercised. 0.0..=100.0.

§branch_pct: Option<f64>

Percentage of branches exercised. Not all builds emit branch counts; None when absent.

§total_lines: u64

Total executable lines.

§covered_lines: u64

Lines exercised at least once.

§total_functions: u64

Total functions.

§covered_functions: u64

Functions called by at least one test.

§total_regions: u64

Total regions.

§covered_regions: u64

Regions exercised at least once.

§files: Vec<FileCoverage>

Per-file breakdown. Empty unless the run was configured with CoverageRun::per_file.

Implementations§

Source§

impl CoverageResult

Source

pub fn into_check_result(self, threshold: CoverageThreshold) -> CheckResult

Convert this result into a CheckResult against the given threshold.

Pass when the measured percentage meets or exceeds the threshold, otherwise fail with Severity::Warning. The verdict carries numeric evidence for both the actual and target percentages.

§Example
use dev_coverage::{CoverageResult, CoverageThreshold};
use dev_report::Verdict;

let r = CoverageResult {
    name: "x".into(), version: "0.1.0".into(),
    line_pct: 90.0, function_pct: 85.0, region_pct: 80.0,
    branch_pct: None,
    total_lines: 100, covered_lines: 90,
    total_functions: 20, covered_functions: 17,
    total_regions: 50, covered_regions: 40,
    files: Vec::new(),
};
let c = r.into_check_result(CoverageThreshold::min_line_pct(80.0));
assert_eq!(c.verdict, Verdict::Pass);
Source

pub fn diff(&self, baseline: &Baseline, tolerance_pct: f64) -> CoverageDiff

Compare this result against a stored baseline.

Returns a CoverageDiff carrying signed deltas for each metric. tolerance_pct is the maximum negative delta tolerated before the diff is flagged as a regression — e.g. tolerance_pct = 1.0 allows up to a 1-percentage-point drop without regressing.

§Example
use dev_coverage::{Baseline, CoverageResult};

let r = CoverageResult {
    name: "x".into(), version: "0.1.0".into(),
    line_pct: 75.0, function_pct: 80.0, region_pct: 70.0,
    branch_pct: None,
    total_lines: 100, covered_lines: 75,
    total_functions: 20, covered_functions: 16,
    total_regions: 50, covered_regions: 35,
    files: Vec::new(),
};
let baseline = Baseline {
    name: "x".into(),
    line_pct: 80.0, function_pct: 85.0, region_pct: 75.0,
};
let diff = r.diff(&baseline, 1.0);
assert!(diff.regressed);
assert_eq!(diff.line_pct_delta, -5.0);
Source

pub fn to_baseline(&self) -> Baseline

Convert this result into a Baseline suitable for persisting.

Source

pub fn least_covered_files(&self, n: usize) -> Vec<&FileCoverage>

Return the n files with the lowest line coverage, sorted ascending.

Useful for emitting evidence about which files most need attention. Returns an empty vector when files was not populated.

Trait Implementations§

Source§

impl Clone for CoverageResult

Source§

fn clone(&self) -> CoverageResult

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CoverageResult

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for CoverageResult

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for CoverageResult

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,