From e53abe3f0bcdb30310452df402bd1afb47aaff62 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Mon, 13 May 2019 22:20:00 +1000 Subject: [PATCH] Improve `ef_tests` errors --- tests/ef_tests/src/lib.rs | 20 ++++++++++++++++---- tests/ef_tests/tests/tests.rs | 6 +----- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/tests/ef_tests/src/lib.rs b/tests/ef_tests/src/lib.rs index bcce9a952..0166a04ec 100644 --- a/tests/ef_tests/src/lib.rs +++ b/tests/ef_tests/src/lib.rs @@ -29,16 +29,23 @@ pub struct SszGenericCase { pub ssz: Option, } +#[derive(Debug, PartialEq, Clone)] +pub struct TestCaseResult { + pub description: String, + pub result: Result<(), Error>, +} + pub trait Test { - fn test(&self) -> Vec>; + fn test(&self) -> Vec; } impl Test for TestDoc { - fn test(&self) -> Vec> { + fn test(&self) -> Vec { self.test_cases .iter() - .map(|tc| { - if let Some(ssz) = &tc.ssz { + .enumerate() + .map(|(i, tc)| { + let result = if let Some(ssz) = &tc.ssz { match tc.type_name.as_ref() { "uint8" => compare_decoding::(tc.valid, ssz, &tc.value), "uint16" => compare_decoding::(tc.valid, ssz, &tc.value), @@ -56,6 +63,11 @@ impl Test for TestDoc { // // See: https://github.com/ethereum/eth2.0-specs/issues/1079 Ok(()) + }; + + TestCaseResult { + description: format!("Case {}: {:?}", i, tc), + result, } }) .collect() diff --git a/tests/ef_tests/tests/tests.rs b/tests/ef_tests/tests/tests.rs index e549da064..13d204c4c 100644 --- a/tests/ef_tests/tests/tests.rs +++ b/tests/ef_tests/tests/tests.rs @@ -23,11 +23,7 @@ fn ssz() { let results = doc.test(); - let failures: Vec<(usize, &Result<_, _>)> = results - .iter() - .enumerate() - .filter(|(_i, r)| r.is_err()) - .collect(); + let failures: Vec<&TestCaseResult> = results.iter().filter(|r| r.result.is_err()).collect(); if !failures.is_empty() { panic!("{:?}", failures);