precept 0.3.0

A testing utility for fuzzing and fault injection to discover erroneous and interesting states.
Documentation
use core::panic;

use super::{Dispatch, Event};

pub struct TestDispatch;

impl Dispatch for TestDispatch {
    fn emit(&self, event: Event) {
        match event {
            Event::RegisterEntry(_) => {
                // noop
            }
            Event::EmitEntry { entry, condition, details } => {
                if !entry.expectation().check(condition) {
                    tracing::error!(
                        details = format!("{}", details),
                        location = ?entry.location(),
                        module = ?entry.module(),
                        function = ?entry.function(),
                        "expectation {:?} failed: {}",
                        entry.expectation(),
                        entry.property()
                    );
                    panic!("expectation failed")
                }
            }
            Event::SetupComplete { details } => {
                tracing::info!(
                    details = serde_json::to_string(&details).unwrap(),
                    "setup complete"
                )
            }
            Event::Custom { name, value } => {
                tracing::info!(
                    name,
                    value = serde_json::to_string(&value).unwrap(),
                    "custom event"
                )
            }
        }
    }

    fn random(&self) -> u64 {
        rand::random()
    }
}