Tidy presentation of errors for ef_tests
This commit is contained in:
parent
892d891977
commit
e760afbc1a
@ -1,7 +1,7 @@
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub struct FieldComparison {
|
||||
pub equal: bool,
|
||||
pub field_name: String,
|
||||
pub equal: bool,
|
||||
pub a: String,
|
||||
pub b: String,
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use super::*;
|
||||
use compare_fields::CompareFields;
|
||||
use compare_fields::{CompareFields, FieldComparison};
|
||||
use std::fmt::Debug;
|
||||
use types::BeaconState;
|
||||
|
||||
@ -51,16 +51,16 @@ where
|
||||
{
|
||||
match (result, expected) {
|
||||
(Ok(result), Some(expected)) => {
|
||||
let mismatching_fields: Vec<String> = expected
|
||||
let mismatching_fields: Vec<FieldComparison> = expected
|
||||
.compare_fields(result)
|
||||
.into_iter()
|
||||
.filter(|c| !c.equal)
|
||||
.map(|c| c.field_name)
|
||||
// .map(|c| c.field_name)
|
||||
.collect();
|
||||
|
||||
if !mismatching_fields.is_empty() {
|
||||
Err(Error::NotEqual(format!(
|
||||
"Result mismatch. Fields not equal: {:?}",
|
||||
"Fields not equal: {:#?}",
|
||||
mismatching_fields
|
||||
)))
|
||||
} else {
|
||||
|
@ -108,9 +108,11 @@ pub fn print_failures(doc: &Doc, results: &[CaseResult]) {
|
||||
println!("");
|
||||
|
||||
for failure in failures {
|
||||
let error = failure.result.clone().unwrap_err();
|
||||
|
||||
println!("-------");
|
||||
println!("case[{}].result:", failure.case_index);
|
||||
println!("{:#?}", failure.result);
|
||||
println!("case[{}] failed with {}:", failure.case_index, error.name());
|
||||
println!("{}", error.message());
|
||||
}
|
||||
println!("");
|
||||
}
|
||||
|
@ -7,3 +7,21 @@ pub enum Error {
|
||||
/// Failed to parse the test (internal error).
|
||||
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