Rename Test
trait to EfTest
This commit is contained in:
parent
57040efc2a
commit
4cb23dd342
@ -1,16 +1,15 @@
|
||||
use super::*;
|
||||
use types::EthSpec;
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub struct TestCaseResult {
|
||||
pub struct CaseResult {
|
||||
pub case_index: usize,
|
||||
pub desc: String,
|
||||
pub result: Result<(), Error>,
|
||||
}
|
||||
|
||||
impl TestCaseResult {
|
||||
impl CaseResult {
|
||||
pub fn new<T: Debug>(case_index: usize, case: &T, result: Result<(), Error>) -> Self {
|
||||
TestCaseResult {
|
||||
CaseResult {
|
||||
case_index,
|
||||
desc: format!("{:?}", case),
|
||||
result,
|
||||
@ -18,10 +17,6 @@ impl TestCaseResult {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Test {
|
||||
fn test<E: EthSpec>(&self) -> Vec<TestCaseResult>;
|
||||
}
|
||||
|
||||
/// Compares `result` with `expected`.
|
||||
///
|
||||
/// If `expected.is_none()` then `result` is expected to be `Err`. Otherwise, `T` in `result` and
|
||||
|
@ -16,8 +16,8 @@ impl YamlDecode for SszGeneric {
|
||||
}
|
||||
}
|
||||
|
||||
impl Test for Cases<SszGeneric> {
|
||||
fn test<E: EthSpec>(&self) -> Vec<TestCaseResult> {
|
||||
impl EfTest for Cases<SszGeneric> {
|
||||
fn test_results<E: EthSpec>(&self) -> Vec<CaseResult> {
|
||||
self.test_cases
|
||||
.iter()
|
||||
.enumerate()
|
||||
@ -42,7 +42,7 @@ impl Test for Cases<SszGeneric> {
|
||||
Ok(())
|
||||
};
|
||||
|
||||
TestCaseResult::new(i, tc, result)
|
||||
CaseResult::new(i, tc, result)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
@ -41,8 +41,8 @@ impl SszStatic {
|
||||
}
|
||||
}
|
||||
|
||||
impl Test for Cases<SszStatic> {
|
||||
fn test<E: EthSpec>(&self) -> Vec<TestCaseResult> {
|
||||
impl EfTest for Cases<SszStatic> {
|
||||
fn test_results<E: EthSpec>(&self) -> Vec<CaseResult> {
|
||||
self.test_cases
|
||||
.iter()
|
||||
.enumerate()
|
||||
@ -76,7 +76,7 @@ impl Test for Cases<SszStatic> {
|
||||
))),
|
||||
};
|
||||
|
||||
TestCaseResult::new(i, tc, result)
|
||||
CaseResult::new(i, tc, result)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ impl Doc {
|
||||
Self { yaml }
|
||||
}
|
||||
|
||||
pub fn get_test_results(path: PathBuf) -> Vec<TestCaseResult> {
|
||||
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();
|
||||
@ -40,7 +40,7 @@ impl Doc {
|
||||
pub fn assert_tests_pass(path: PathBuf) {
|
||||
let results = Self::get_test_results(path);
|
||||
|
||||
let failures: Vec<&TestCaseResult> = results.iter().filter(|r| r.result.is_err()).collect();
|
||||
let failures: Vec<&CaseResult> = results.iter().filter(|r| r.result.is_err()).collect();
|
||||
|
||||
if !failures.is_empty() {
|
||||
for f in &failures {
|
||||
@ -52,13 +52,13 @@ impl Doc {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_test<T, E: EthSpec>(test_doc_yaml: &String) -> Vec<TestCaseResult>
|
||||
pub fn run_test<T, E: EthSpec>(test_doc_yaml: &String) -> Vec<CaseResult>
|
||||
where
|
||||
Cases<T>: Test + serde::de::DeserializeOwned + YamlDecode,
|
||||
Cases<T>: EfTest + serde::de::DeserializeOwned + YamlDecode,
|
||||
{
|
||||
let test_cases_yaml = extract_yaml_by_key(test_doc_yaml, "test_cases");
|
||||
|
||||
let test_cases: Cases<T> = Cases::yaml_decode(&test_cases_yaml.to_string()).unwrap();
|
||||
|
||||
test_cases.test::<E>()
|
||||
test_cases.test_results::<E>()
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ use ethereum_types::{U128, U256};
|
||||
use serde_derive::Deserialize;
|
||||
use ssz::Decode;
|
||||
use std::fmt::Debug;
|
||||
use types::EthSpec;
|
||||
|
||||
pub use crate::case_result::*;
|
||||
pub use crate::cases::*;
|
||||
@ -19,3 +20,10 @@ mod doc_header;
|
||||
mod error;
|
||||
mod eth_specs;
|
||||
mod yaml_decode;
|
||||
|
||||
/// Defined where an object can return the results of some test(s) adhering to the Ethereum
|
||||
/// Foundation testing format.
|
||||
pub trait EfTest {
|
||||
/// Returns the results of executing one or more tests.
|
||||
fn test_results<E: EthSpec>(&self) -> Vec<CaseResult>;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user