Tidy ef_test failure message

This commit is contained in:
Paul Hauner 2019-05-15 12:30:42 +10:00
parent 035e124a14
commit faac5ca10c
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6
2 changed files with 39 additions and 19 deletions

View File

@ -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<CaseResult> {
let doc = Self::from_path(path);
let header: DocHeader = serde_yaml::from_str(&doc.yaml.as_str()).unwrap();
pub fn test_results(&self) -> Vec<CaseResult> {
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::<SszGeneric, FoundationEthSpec>(&doc.yaml),
("ssz", "static", "minimal") => run_test::<SszStatic, MinimalEthSpec>(&doc.yaml),
("ssz", "uint", _) => run_test::<SszGeneric, FoundationEthSpec>(&self.yaml),
("ssz", "static", "minimal") => run_test::<SszStatic, MinimalEthSpec>(&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::<E>()
}
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!("");
}

View File

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