Improve ef_tests errors

This commit is contained in:
Paul Hauner 2019-05-13 22:20:00 +10:00
parent 068b6fafde
commit e53abe3f0b
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C
2 changed files with 17 additions and 9 deletions

View File

@ -29,16 +29,23 @@ pub struct SszGenericCase {
pub ssz: Option<String>, pub ssz: Option<String>,
} }
#[derive(Debug, PartialEq, Clone)]
pub struct TestCaseResult {
pub description: String,
pub result: Result<(), Error>,
}
pub trait Test { pub trait Test {
fn test(&self) -> Vec<Result<(), Error>>; fn test(&self) -> Vec<TestCaseResult>;
} }
impl Test for TestDoc<SszGenericCase> { impl Test for TestDoc<SszGenericCase> {
fn test(&self) -> Vec<Result<(), Error>> { fn test(&self) -> Vec<TestCaseResult> {
self.test_cases self.test_cases
.iter() .iter()
.map(|tc| { .enumerate()
if let Some(ssz) = &tc.ssz { .map(|(i, tc)| {
let result = if let Some(ssz) = &tc.ssz {
match tc.type_name.as_ref() { match tc.type_name.as_ref() {
"uint8" => compare_decoding::<u8>(tc.valid, ssz, &tc.value), "uint8" => compare_decoding::<u8>(tc.valid, ssz, &tc.value),
"uint16" => compare_decoding::<u16>(tc.valid, ssz, &tc.value), "uint16" => compare_decoding::<u16>(tc.valid, ssz, &tc.value),
@ -56,6 +63,11 @@ impl Test for TestDoc<SszGenericCase> {
// //
// See: https://github.com/ethereum/eth2.0-specs/issues/1079 // See: https://github.com/ethereum/eth2.0-specs/issues/1079
Ok(()) Ok(())
};
TestCaseResult {
description: format!("Case {}: {:?}", i, tc),
result,
} }
}) })
.collect() .collect()

View File

@ -23,11 +23,7 @@ fn ssz() {
let results = doc.test(); let results = doc.test();
let failures: Vec<(usize, &Result<_, _>)> = results let failures: Vec<&TestCaseResult> = results.iter().filter(|r| r.result.is_err()).collect();
.iter()
.enumerate()
.filter(|(_i, r)| r.is_err())
.collect();
if !failures.is_empty() { if !failures.is_empty() {
panic!("{:?}", failures); panic!("{:?}", failures);