mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-19 22:08:30 +00:00
Re-organise ef_tests
This commit is contained in:
@@ -6,73 +6,14 @@ use std::fmt::Debug;
|
||||
use test_decode::TestDecode;
|
||||
|
||||
pub use crate::error::*;
|
||||
pub use crate::ssz_generic::*;
|
||||
pub use crate::test_case_result::*;
|
||||
pub use crate::test_doc::*;
|
||||
pub use crate::test_doc_cases::*;
|
||||
pub use crate::test_doc_header::*;
|
||||
|
||||
mod error;
|
||||
mod ssz_generic;
|
||||
mod ssz_static;
|
||||
mod test_case_result;
|
||||
mod test_decode;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct TestDoc<T> {
|
||||
pub title: String,
|
||||
pub summary: String,
|
||||
pub forks_timeline: String,
|
||||
pub forks: Vec<String>,
|
||||
pub config: String,
|
||||
pub runner: String,
|
||||
pub handler: String,
|
||||
pub test_cases: Vec<T>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub struct TestCaseResult<T> {
|
||||
pub case_index: usize,
|
||||
pub case: T,
|
||||
pub result: Result<(), Error>,
|
||||
}
|
||||
|
||||
pub trait Test<T> {
|
||||
fn test(&self) -> Vec<TestCaseResult<T>>;
|
||||
}
|
||||
|
||||
/// Compares `result` with `expected`.
|
||||
///
|
||||
/// If `expected.is_none()` then `result` is expected to be `Err`. Otherwise, `T` in `result` and
|
||||
/// `expected` must be equal.
|
||||
fn compare_result<T, E>(result: Result<T, E>, expected: Option<T>) -> Result<(), Error>
|
||||
where
|
||||
T: PartialEq<T> + Debug,
|
||||
E: Debug,
|
||||
{
|
||||
match (result, expected) {
|
||||
// Pass: The should have failed and did fail.
|
||||
(Err(_), None) => Ok(()),
|
||||
// Fail: The test failed when it should have produced a result (fail).
|
||||
(Err(e), Some(expected)) => Err(Error::NotEqual(format!(
|
||||
"Got {:?} expected {:?}",
|
||||
e, expected
|
||||
))),
|
||||
// Fail: The test produced a result when it should have failed (fail).
|
||||
(Ok(result), None) => Err(Error::DidntFail(format!("Got {:?}", result))),
|
||||
// Potential Pass: The test should have produced a result, and it did.
|
||||
(Ok(result), Some(expected)) => {
|
||||
if result == expected {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Error::NotEqual(format!(
|
||||
"Got {:?} expected {:?}",
|
||||
result, expected
|
||||
)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn it_works() {
|
||||
assert_eq!(2 + 2, 4);
|
||||
}
|
||||
}
|
||||
mod test_doc;
|
||||
mod test_doc_cases;
|
||||
mod test_doc_header;
|
||||
|
||||
Reference in New Issue
Block a user