Tidy presentation of errors for ef_tests

This commit is contained in:
Paul Hauner 2019-05-22 18:55:00 +10:00
parent 892d891977
commit e760afbc1a
No known key found for this signature in database
GPG Key ID: 5E2CFF9B75FA63DF
4 changed files with 27 additions and 7 deletions

View File

@ -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,
}

View File

@ -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 {

View File

@ -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!("");
}

View File

@ -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(),
}
}
}