2019-05-13 12:10:23 +00:00
|
|
|
use error::Error;
|
2019-05-13 12:14:47 +00:00
|
|
|
use ethereum_types::{U128, U256};
|
2019-05-13 07:56:46 +00:00
|
|
|
use serde_derive::Deserialize;
|
2019-05-13 12:10:23 +00:00
|
|
|
use ssz::Decode;
|
|
|
|
use std::fmt::Debug;
|
|
|
|
use test_decode::TestDecode;
|
|
|
|
|
2019-05-14 00:01:20 +00:00
|
|
|
pub use crate::error::*;
|
2019-05-13 23:36:25 +00:00
|
|
|
pub use crate::ssz_generic::*;
|
|
|
|
|
2019-05-13 12:10:23 +00:00
|
|
|
mod error;
|
2019-05-13 23:36:25 +00:00
|
|
|
mod ssz_generic;
|
2019-05-14 00:01:20 +00:00
|
|
|
mod ssz_static;
|
2019-05-13 12:10:23 +00:00
|
|
|
mod test_decode;
|
2019-05-13 07:56:46 +00:00
|
|
|
|
|
|
|
#[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>,
|
|
|
|
}
|
|
|
|
|
2019-05-13 12:20:00 +00:00
|
|
|
#[derive(Debug, PartialEq, Clone)]
|
2019-05-13 23:27:27 +00:00
|
|
|
pub struct TestCaseResult<T> {
|
|
|
|
pub case_index: usize,
|
|
|
|
pub case: T,
|
2019-05-13 12:20:00 +00:00
|
|
|
pub result: Result<(), Error>,
|
|
|
|
}
|
|
|
|
|
2019-05-13 23:27:27 +00:00
|
|
|
pub trait Test<T> {
|
|
|
|
fn test(&self) -> Vec<TestCaseResult<T>>;
|
2019-05-13 12:10:23 +00:00
|
|
|
}
|
|
|
|
|
2019-05-13 23:36:25 +00:00
|
|
|
/// Compares `result` with `expected`.
|
|
|
|
///
|
|
|
|
/// If `expected.is_none()` then `result` is expected to be `Err`. Otherwise, `T` in `result` and
|
|
|
|
/// `expected` must be equal.
|
2019-05-13 23:27:27 +00:00
|
|
|
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
|
|
|
|
)))
|
|
|
|
}
|
2019-05-13 12:10:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-13 07:56:46 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
#[test]
|
|
|
|
fn it_works() {
|
|
|
|
assert_eq!(2 + 2, 4);
|
|
|
|
}
|
|
|
|
}
|