Skip to main content

Report

Struct Report 

Source
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: u32

Schema version for this report format.

§subject: String

Crate or project being reported on.

§subject_version: String

Version 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

Source

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);
Source

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"));
Source

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);
Source

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());
Source

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 Skip or 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);
Source

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);
Source

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\""));
Source

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");
Source

pub fn to_terminal(&self) -> String

Available on crate feature terminal only.

Render this report to a TTY-friendly string. Monochrome.

Available with the terminal feature.

Source

pub fn to_terminal_color(&self) -> String

Available on crate feature terminal only.

Render this report with ANSI color codes.

Available with the terminal feature.

Source

pub fn to_markdown(&self) -> String

Available on crate feature markdown only.

Render this report to a Markdown string.

Available with the markdown feature.

Source

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()]);
Source

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);

Trait Implementations§

Source§

impl Clone for Report

Source§

fn clone(&self) -> Report

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 Report

Source§

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

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

impl<'de> Deserialize<'de> for Report

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 Report

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>,