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: StringCrate or subject name (descriptive; matches the Report subject).
version: StringSubject version (descriptive; matches the Report subject_version).
line_pct: f64Percentage of executable lines exercised by tests. 0.0..=100.0.
function_pct: f64Percentage of functions called by tests. 0.0..=100.0.
region_pct: f64Percentage 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: u64Total executable lines.
covered_lines: u64Lines exercised at least once.
total_functions: u64Total functions.
covered_functions: u64Functions called by at least one test.
total_regions: u64Total regions.
covered_regions: u64Regions exercised at least once.
files: Vec<FileCoverage>Per-file breakdown. Empty unless the run was configured with
CoverageRun::per_file.
Implementations§
Source§impl CoverageResult
impl CoverageResult
Sourcepub fn into_check_result(self, threshold: CoverageThreshold) -> CheckResult
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);Sourcepub fn diff(&self, baseline: &Baseline, tolerance_pct: f64) -> CoverageDiff
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);Sourcepub fn to_baseline(&self) -> Baseline
pub fn to_baseline(&self) -> Baseline
Convert this result into a Baseline suitable for persisting.
Sourcepub fn least_covered_files(&self, n: usize) -> Vec<&FileCoverage>
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
impl Clone for CoverageResult
Source§fn clone(&self) -> CoverageResult
fn clone(&self) -> CoverageResult
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more