mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2025-01-07 11:32:21 +00:00
Replace TestDoc
with Doc
This commit is contained in:
parent
b7a8613444
commit
2b8e8ce59e
@ -4,11 +4,11 @@ use std::{fs::File, io::prelude::*, path::PathBuf};
|
||||
use types::{EthSpec, FoundationEthSpec};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct TestDoc {
|
||||
pub struct Doc {
|
||||
pub yaml: String,
|
||||
}
|
||||
|
||||
impl TestDoc {
|
||||
impl Doc {
|
||||
fn from_path(path: PathBuf) -> Self {
|
||||
let mut file = File::open(path).unwrap();
|
||||
|
||||
@ -21,7 +21,7 @@ impl TestDoc {
|
||||
pub fn get_test_results(path: PathBuf) -> Vec<TestCaseResult> {
|
||||
let doc = Self::from_path(path);
|
||||
|
||||
let header: TestDocHeader = serde_yaml::from_str(&doc.yaml.as_str()).unwrap();
|
||||
let header: DocHeader = serde_yaml::from_str(&doc.yaml.as_str()).unwrap();
|
||||
|
||||
match (
|
||||
header.runner.as_ref(),
|
||||
@ -54,12 +54,11 @@ impl TestDoc {
|
||||
|
||||
pub fn run_test<T, E: EthSpec>(test_doc_yaml: &String) -> Vec<TestCaseResult>
|
||||
where
|
||||
TestDocCases<T>: Test + serde::de::DeserializeOwned + YamlDecode,
|
||||
DocCases<T>: Test + serde::de::DeserializeOwned + YamlDecode,
|
||||
{
|
||||
let test_cases_yaml = extract_yaml_by_key(test_doc_yaml, "test_cases");
|
||||
|
||||
let test_cases: TestDocCases<T> =
|
||||
TestDocCases::yaml_decode(&test_cases_yaml.to_string()).unwrap();
|
||||
let test_cases: DocCases<T> = DocCases::yaml_decode(&test_cases_yaml.to_string()).unwrap();
|
||||
|
||||
test_cases.test::<E>()
|
||||
}
|
@ -9,11 +9,11 @@ pub use ssz_generic::*;
|
||||
pub use ssz_static::*;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct TestDocCases<T> {
|
||||
pub struct DocCases<T> {
|
||||
pub test_cases: Vec<T>,
|
||||
}
|
||||
|
||||
impl<T: YamlDecode> YamlDecode for TestDocCases<T> {
|
||||
impl<T: YamlDecode> YamlDecode for DocCases<T> {
|
||||
/// Decodes a YAML list of test cases
|
||||
fn yaml_decode(yaml: &String) -> Result<Self, Error> {
|
||||
let doc = &YamlLoader::load_from_str(yaml).unwrap()[0];
|
@ -16,7 +16,7 @@ impl YamlDecode for SszGeneric {
|
||||
}
|
||||
}
|
||||
|
||||
impl Test for TestDocCases<SszGeneric> {
|
||||
impl Test for DocCases<SszGeneric> {
|
||||
fn test<E: EthSpec>(&self) -> Vec<TestCaseResult> {
|
||||
self.test_cases
|
||||
.iter()
|
@ -41,7 +41,7 @@ impl SszStatic {
|
||||
}
|
||||
}
|
||||
|
||||
impl Test for TestDocCases<SszStatic> {
|
||||
impl Test for DocCases<SszStatic> {
|
||||
fn test<E: EthSpec>(&self) -> Vec<TestCaseResult> {
|
||||
self.test_cases
|
||||
.iter()
|
@ -1,7 +1,7 @@
|
||||
use super::*;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct TestDocHeader {
|
||||
pub struct DocHeader {
|
||||
pub title: String,
|
||||
pub summary: String,
|
||||
pub forks_timeline: String,
|
@ -4,18 +4,18 @@ use serde_derive::Deserialize;
|
||||
use ssz::Decode;
|
||||
use std::fmt::Debug;
|
||||
|
||||
pub use crate::case_result::*;
|
||||
pub use crate::doc::*;
|
||||
pub use crate::doc_cases::*;
|
||||
pub use crate::doc_header::*;
|
||||
pub use crate::error::*;
|
||||
pub use crate::eth_specs::*;
|
||||
pub use crate::test_case_result::*;
|
||||
pub use crate::test_doc::*;
|
||||
pub use crate::test_doc_cases::*;
|
||||
pub use crate::test_doc_header::*;
|
||||
pub use yaml_decode::YamlDecode;
|
||||
|
||||
mod case_result;
|
||||
mod doc;
|
||||
mod doc_cases;
|
||||
mod doc_header;
|
||||
mod error;
|
||||
mod eth_specs;
|
||||
mod test_case_result;
|
||||
mod test_doc;
|
||||
mod test_doc_cases;
|
||||
mod test_doc_header;
|
||||
mod yaml_decode;
|
||||
|
@ -21,17 +21,17 @@ mod ssz_generic {
|
||||
|
||||
#[test]
|
||||
fn uint_bounds() {
|
||||
TestDoc::assert_tests_pass(ssz_generic_file("uint/uint_bounds.yaml"));
|
||||
Doc::assert_tests_pass(ssz_generic_file("uint/uint_bounds.yaml"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uint_random() {
|
||||
TestDoc::assert_tests_pass(ssz_generic_file("uint/uint_random.yaml"));
|
||||
Doc::assert_tests_pass(ssz_generic_file("uint/uint_random.yaml"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uint_wrong_length() {
|
||||
TestDoc::assert_tests_pass(ssz_generic_file("uint/uint_wrong_length.yaml"));
|
||||
Doc::assert_tests_pass(ssz_generic_file("uint/uint_wrong_length.yaml"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,6 +48,6 @@ mod ssz_static {
|
||||
|
||||
#[test]
|
||||
fn minimal_nil() {
|
||||
TestDoc::assert_tests_pass(ssz_generic_file("core/ssz_minimal_nil.yaml"));
|
||||
Doc::assert_tests_pass(ssz_generic_file("core/ssz_minimal_nil.yaml"));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user