pub struct Report {
pub schema_version: u32,
pub subject: String,
pub subject_version: String,
pub producer: Option<String>,
pub started_at: DateTime<Utc>,
pub finished_at: Option<DateTime<Utc>>,
pub checks: Vec<CheckResult>,
}Expand description
A full report. The output of one verification run.
§Example
use dev_report::{CheckResult, Report, Verdict};
let mut r = Report::new("my-crate", "0.1.0").with_producer("my-harness");
r.push(CheckResult::pass("compile"));
r.finish();
assert_eq!(r.overall_verdict(), Verdict::Pass);Fields§
§schema_version: u32Schema version for this report format.
subject: StringCrate or project being reported on.
subject_version: StringVersion of the subject at the time of the run.
producer: Option<String>Producer of the report (e.g. dev-bench, dev-async).
started_at: DateTime<Utc>Time the report was started.
finished_at: Option<DateTime<Utc>>Time the report was finalized.
checks: Vec<CheckResult>All individual check results in this report.
Implementations§
Source§impl Report
impl Report
Sourcepub fn new(
subject: impl Into<String>,
subject_version: impl Into<String>,
) -> Self
pub fn new( subject: impl Into<String>, subject_version: impl Into<String>, ) -> Self
Begin a new report for the given subject and version.
§Example
use dev_report::Report;
let r = Report::new("my-crate", "0.1.0");
assert_eq!(r.subject, "my-crate");
assert_eq!(r.schema_version, 1);Sourcepub fn with_producer(self, producer: impl Into<String>) -> Self
pub fn with_producer(self, producer: impl Into<String>) -> Self
Set the producer of this report.
§Example
use dev_report::Report;
let r = Report::new("crate", "0.1.0").with_producer("dev-bench");
assert_eq!(r.producer.as_deref(), Some("dev-bench"));Sourcepub fn push(&mut self, result: CheckResult)
pub fn push(&mut self, result: CheckResult)
Append a check result to this report.
§Example
use dev_report::{CheckResult, Report};
let mut r = Report::new("crate", "0.1.0");
r.push(CheckResult::pass("compile"));
assert_eq!(r.checks.len(), 1);Sourcepub fn finish(&mut self)
pub fn finish(&mut self)
Mark the report as finished, stamping the finish time.
§Example
use dev_report::Report;
let mut r = Report::new("crate", "0.1.0");
r.finish();
assert!(r.finished_at.is_some());Sourcepub fn overall_verdict(&self) -> Verdict
pub fn overall_verdict(&self) -> Verdict
Compute the overall verdict for this report.
Rules:
- Any
Fail->Fail - Else any
Warn->Warn - Else any
Pass->Pass - Else (all
Skipor empty) ->Skip
§Example
use dev_report::{CheckResult, Report, Severity, Verdict};
let mut r = Report::new("crate", "0.1.0");
r.push(CheckResult::pass("a"));
r.push(CheckResult::fail("b", Severity::Error));
assert_eq!(r.overall_verdict(), Verdict::Fail);Sourcepub fn checks_with_tag<'a>(
&'a self,
tag: &'a str,
) -> impl Iterator<Item = &'a CheckResult>
pub fn checks_with_tag<'a>( &'a self, tag: &'a str, ) -> impl Iterator<Item = &'a CheckResult>
Iterate over checks that carry the given tag.
§Example
use dev_report::{CheckResult, Report};
let mut r = Report::new("crate", "0.1.0");
r.push(CheckResult::pass("a").with_tag("slow"));
r.push(CheckResult::pass("b"));
r.push(CheckResult::pass("c").with_tag("slow"));
let slow: Vec<_> = r.checks_with_tag("slow").collect();
assert_eq!(slow.len(), 2);Sourcepub fn to_json(&self) -> Result<String>
pub fn to_json(&self) -> Result<String>
Serialize this report to JSON.
§Example
use dev_report::Report;
let r = Report::new("crate", "0.1.0");
let json = r.to_json().unwrap();
assert!(json.contains("\"subject\": \"crate\""));Sourcepub fn from_json(s: &str) -> Result<Self>
pub fn from_json(s: &str) -> Result<Self>
Deserialize a report from JSON.
§Example
use dev_report::Report;
let r = Report::new("crate", "0.1.0");
let json = r.to_json().unwrap();
let parsed = Report::from_json(&json).unwrap();
assert_eq!(parsed.subject, "crate");Sourcepub fn to_terminal(&self) -> String
Available on crate feature terminal only.
pub fn to_terminal(&self) -> String
terminal only.Render this report to a TTY-friendly string. Monochrome.
Available with the terminal feature.
Sourcepub fn to_terminal_color(&self) -> String
Available on crate feature terminal only.
pub fn to_terminal_color(&self) -> String
terminal only.Render this report with ANSI color codes.
Available with the terminal feature.
Sourcepub fn to_markdown(&self) -> String
Available on crate feature markdown only.
pub fn to_markdown(&self) -> String
markdown only.Render this report to a Markdown string.
Available with the markdown feature.
Sourcepub fn diff(&self, baseline: &Self) -> Diff
pub fn diff(&self, baseline: &Self) -> Diff
Compare this report against a baseline using default options.
self is the new report; baseline is the previous one.
Default options flag duration regressions over 20% slower.
§Example
use dev_report::{CheckResult, Report, Severity};
let mut prev = Report::new("c", "0.1.0");
prev.push(CheckResult::pass("a"));
let mut curr = Report::new("c", "0.1.0");
curr.push(CheckResult::fail("a", Severity::Error));
let diff = curr.diff(&prev);
assert_eq!(diff.newly_failing, vec!["a".to_string()]);Sourcepub fn diff_with(&self, baseline: &Self, opts: &DiffOptions) -> Diff
pub fn diff_with(&self, baseline: &Self, opts: &DiffOptions) -> Diff
Compare this report against a baseline using custom options.
§Example
use dev_report::{CheckResult, DiffOptions, Report};
let mut prev = Report::new("c", "0.1.0");
prev.push(CheckResult::pass("a").with_duration_ms(100));
let mut curr = Report::new("c", "0.1.0");
curr.push(CheckResult::pass("a").with_duration_ms(150));
let opts = DiffOptions {
duration_regression_pct: Some(10.0),
duration_regression_abs_ms: None,
};
let diff = curr.diff_with(&prev, &opts);
assert_eq!(diff.duration_regressions.len(), 1);