From faac5ca10cdc25b89f3b1f2971a2f7f789e4387c Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Wed, 15 May 2019 12:30:42 +1000 Subject: [PATCH] Tidy `ef_test` failure message --- tests/ef_tests/src/doc.rs | 56 ++++++++++++++++++++++++----------- tests/ef_tests/tests/tests.rs | 2 -- 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/tests/ef_tests/src/doc.rs b/tests/ef_tests/src/doc.rs index 0182e7479..7b486d2e8 100644 --- a/tests/ef_tests/src/doc.rs +++ b/tests/ef_tests/src/doc.rs @@ -11,30 +11,29 @@ use types::{EthSpec, FoundationEthSpec}; #[derive(Debug, Deserialize)] pub struct Doc { pub yaml: String, + pub path: PathBuf, } impl Doc { fn from_path(path: PathBuf) -> Self { - let mut file = File::open(path).unwrap(); + let mut file = File::open(path.clone()).unwrap(); let mut yaml = String::new(); file.read_to_string(&mut yaml).unwrap(); - Self { yaml } + Self { yaml, path } } - pub fn get_test_results(path: PathBuf) -> Vec { - let doc = Self::from_path(path); - - let header: DocHeader = serde_yaml::from_str(&doc.yaml.as_str()).unwrap(); + pub fn test_results(&self) -> Vec { + let header: DocHeader = serde_yaml::from_str(&self.yaml.as_str()).unwrap(); match ( header.runner.as_ref(), header.handler.as_ref(), header.config.as_ref(), ) { - ("ssz", "uint", _) => run_test::(&doc.yaml), - ("ssz", "static", "minimal") => run_test::(&doc.yaml), + ("ssz", "uint", _) => run_test::(&self.yaml), + ("ssz", "static", "minimal") => run_test::(&self.yaml), (runner, handler, config) => panic!( "No implementation for runner: \"{}\", handler: \"{}\", config: \"{}\"", runner, handler, config @@ -43,16 +42,12 @@ impl Doc { } pub fn assert_tests_pass(path: PathBuf) { - let results = Self::get_test_results(path); + let doc = Self::from_path(path); + let results = doc.test_results(); - let failures: Vec<&CaseResult> = results.iter().filter(|r| r.result.is_err()).collect(); - - if !failures.is_empty() { - for f in &failures { - dbg!(&f.case_index); - dbg!(&f.result); - } - panic!("{}/{} tests failed.", failures.len(), results.len()) + if results.iter().any(|r| r.result.is_err()) { + print_failures(&doc, &results); + panic!("Tests failed (see above)"); } } } @@ -69,3 +64,30 @@ where test_cases.test_results::() } + +pub fn print_failures(doc: &Doc, results: &[CaseResult]) { + let header: DocHeader = serde_yaml::from_str(&doc.yaml).unwrap(); + let failures: Vec<&CaseResult> = results.iter().filter(|r| r.result.is_err()).collect(); + + println!("--------------------------------------------------"); + println!("Test Failure"); + println!("Title: {}", header.title); + println!("File: {:?}", doc.path); + println!(""); + println!( + "{} tests, {} failures, {} passes.", + results.len(), + failures.len(), + results.len() - failures.len() + ); + println!(""); + + for failure in failures { + println!("-------"); + println!( + "case[{}] failed with: {:#?}", + failure.case_index, failure.result + ); + } + println!(""); +} diff --git a/tests/ef_tests/tests/tests.rs b/tests/ef_tests/tests/tests.rs index 51083ae47..2497c801d 100644 --- a/tests/ef_tests/tests/tests.rs +++ b/tests/ef_tests/tests/tests.rs @@ -14,7 +14,6 @@ mod ssz_generic { fn ssz_generic_file(file: &str) -> PathBuf { let mut path = test_file("ssz_generic"); path.push(file); - dbg!(&path); path } @@ -41,7 +40,6 @@ mod ssz_static { fn ssz_generic_file(file: &str) -> PathBuf { let mut path = test_file("ssz_static"); path.push(file); - dbg!(&path); path }