use std::fmt;
use crate::common::Branch;
#[derive(Eq, PartialEq, Hash, Debug)]
pub struct Step {
pub name: &'static str,
pub branch: Branch,
}
#[derive(Eq, PartialEq, Hash)]
pub struct Trace {
pub path: Vec<Step>,
}
impl fmt::Debug for Trace {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for (n, step) in self.path.iter().enumerate() {
#[cfg(feature = "fancy-traces")]
{
if n > 0 {
write!(f, "→")?;
}
use colored::Colorize;
write!(
f,
"({}{})",
match step.branch {
Branch::Skip => "",
Branch::Activate => "💥",
},
match step.branch {
Branch::Skip => step.name.green(),
Branch::Activate => step.name.red(),
}
)?;
}
#[cfg(not(feature = "fancy-traces"))]
{
if n > 0 {
write!(f, "->")?;
}
write!(
f,
"({}{})",
match step.branch {
Branch::Skip => "",
Branch::Activate => "!",
},
step.name,
)?;
}
}
Ok(())
}
}
impl Trace {
pub fn failpoint_status_first(&self, failpoint_name: &str) -> Option<Branch> {
for step in &self.path {
if step.name == failpoint_name {
return Some(step.branch);
}
}
None
}
pub fn failpoint_status_last(&self, failpoint_name: &str) -> Option<Branch> {
for step in self.path.iter().rev() {
if step.name == failpoint_name {
return Some(step.branch);
}
}
None
}
}
#[derive(Debug)]
pub struct Report {
pub traces: Vec<Trace>,
pub is_exhaustive: bool,
}
impl PartialEq for Report {
fn eq(&self, other: &Self) -> bool {
use std::collections::HashSet;
self.traces.iter().collect::<HashSet<_>>() == other.traces.iter().collect::<HashSet<_>>()
&& self.is_exhaustive == other.is_exhaustive
}
}
impl Eq for Report {}