mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2025-01-12 14:00:06 +00:00
Tidy presentation of errors for ef_tests
This commit is contained in:
parent
892d891977
commit
e760afbc1a
@ -1,7 +1,7 @@
|
|||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub struct FieldComparison {
|
pub struct FieldComparison {
|
||||||
pub equal: bool,
|
|
||||||
pub field_name: String,
|
pub field_name: String,
|
||||||
|
pub equal: bool,
|
||||||
pub a: String,
|
pub a: String,
|
||||||
pub b: String,
|
pub b: String,
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
use compare_fields::CompareFields;
|
use compare_fields::{CompareFields, FieldComparison};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use types::BeaconState;
|
use types::BeaconState;
|
||||||
|
|
||||||
@ -51,16 +51,16 @@ where
|
|||||||
{
|
{
|
||||||
match (result, expected) {
|
match (result, expected) {
|
||||||
(Ok(result), Some(expected)) => {
|
(Ok(result), Some(expected)) => {
|
||||||
let mismatching_fields: Vec<String> = expected
|
let mismatching_fields: Vec<FieldComparison> = expected
|
||||||
.compare_fields(result)
|
.compare_fields(result)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|c| !c.equal)
|
.filter(|c| !c.equal)
|
||||||
.map(|c| c.field_name)
|
// .map(|c| c.field_name)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if !mismatching_fields.is_empty() {
|
if !mismatching_fields.is_empty() {
|
||||||
Err(Error::NotEqual(format!(
|
Err(Error::NotEqual(format!(
|
||||||
"Result mismatch. Fields not equal: {:?}",
|
"Fields not equal: {:#?}",
|
||||||
mismatching_fields
|
mismatching_fields
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
|
@ -108,9 +108,11 @@ pub fn print_failures(doc: &Doc, results: &[CaseResult]) {
|
|||||||
println!("");
|
println!("");
|
||||||
|
|
||||||
for failure in failures {
|
for failure in failures {
|
||||||
|
let error = failure.result.clone().unwrap_err();
|
||||||
|
|
||||||
println!("-------");
|
println!("-------");
|
||||||
println!("case[{}].result:", failure.case_index);
|
println!("case[{}] failed with {}:", failure.case_index, error.name());
|
||||||
println!("{:#?}", failure.result);
|
println!("{}", error.message());
|
||||||
}
|
}
|
||||||
println!("");
|
println!("");
|
||||||
}
|
}
|
||||||
|
@ -7,3 +7,21 @@ pub enum Error {
|
|||||||
/// Failed to parse the test (internal error).
|
/// Failed to parse the test (internal error).
|
||||||
FailedToParseTest(String),
|
FailedToParseTest(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Error {
|
||||||
|
pub fn name(&self) -> &str {
|
||||||
|
match self {
|
||||||
|
Error::NotEqual(_) => "NotEqual",
|
||||||
|
Error::DidntFail(_) => "DidntFail",
|
||||||
|
Error::FailedToParseTest(_) => "FailedToParseTest",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn message(&self) -> &str {
|
||||||
|
match self {
|
||||||
|
Error::NotEqual(m) => m.as_str(),
|
||||||
|
Error::DidntFail(m) => m.as_str(),
|
||||||
|
Error::FailedToParseTest(m) => m.as_str(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user