2018-06-03 18:04:58 +03:00
|
|
|
use std::borrow::Cow;
|
|
|
|
|
|
2020-07-02 11:15:56 +03:00
|
|
|
pub enum StepResult {
|
|
|
|
|
Success,
|
|
|
|
|
Failure,
|
|
|
|
|
Ignored,
|
2020-08-21 23:04:36 +03:00
|
|
|
Skipped(String),
|
2020-07-02 11:15:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl StepResult {
|
2020-08-21 23:04:36 +03:00
|
|
|
pub fn failed(&self) -> bool {
|
2021-10-28 22:05:35 +03:00
|
|
|
match self {
|
|
|
|
|
StepResult::Success | StepResult::Ignored | StepResult::Skipped(_) => false,
|
|
|
|
|
StepResult::Failure => true,
|
|
|
|
|
}
|
2020-07-02 11:15:56 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-27 18:06:24 +03:00
|
|
|
type CowString<'a> = Cow<'a, str>;
|
2020-07-02 11:15:56 +03:00
|
|
|
type ReportData<'a> = Vec<(CowString<'a>, StepResult)>;
|
2018-08-24 21:52:17 +03:00
|
|
|
pub struct Report<'a> {
|
2020-07-02 11:15:56 +03:00
|
|
|
data: ReportData<'a>,
|
2018-08-24 21:52:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a> Report<'a> {
|
|
|
|
|
pub fn new() -> Self {
|
|
|
|
|
Self { data: Vec::new() }
|
|
|
|
|
}
|
2018-06-03 18:04:58 +03:00
|
|
|
|
2020-07-02 11:15:56 +03:00
|
|
|
pub fn push_result<M>(&mut self, result: Option<(M, StepResult)>)
|
2018-08-24 21:52:17 +03:00
|
|
|
where
|
|
|
|
|
M: Into<CowString<'a>>,
|
|
|
|
|
{
|
|
|
|
|
if let Some((key, success)) = result {
|
|
|
|
|
let key = key.into();
|
|
|
|
|
|
|
|
|
|
debug_assert!(!self.data.iter().any(|(k, _)| k == &key), "{} already reported", key);
|
|
|
|
|
self.data.push((key, success));
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-06 15:32:38 +03:00
|
|
|
|
2020-07-02 11:15:56 +03:00
|
|
|
pub fn data(&self) -> &ReportData<'a> {
|
2018-08-24 21:52:17 +03:00
|
|
|
&self.data
|
2018-06-06 15:32:38 +03:00
|
|
|
}
|
|
|
|
|
}
|