Replace TestDoc with Doc

This commit is contained in:
Paul Hauner 2019-05-15 11:15:34 +10:00
parent b7a8613444
commit 2b8e8ce59e
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6
8 changed files with 22 additions and 23 deletions

View File

@ -4,11 +4,11 @@ use std::{fs::File, io::prelude::*, path::PathBuf};
use types::{EthSpec, FoundationEthSpec}; use types::{EthSpec, FoundationEthSpec};
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct TestDoc { pub struct Doc {
pub yaml: String, pub yaml: String,
} }
impl TestDoc { impl Doc {
fn from_path(path: PathBuf) -> Self { fn from_path(path: PathBuf) -> Self {
let mut file = File::open(path).unwrap(); let mut file = File::open(path).unwrap();
@ -21,7 +21,7 @@ impl TestDoc {
pub fn get_test_results(path: PathBuf) -> Vec<TestCaseResult> { pub fn get_test_results(path: PathBuf) -> Vec<TestCaseResult> {
let doc = Self::from_path(path); 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 ( match (
header.runner.as_ref(), header.runner.as_ref(),
@ -54,12 +54,11 @@ impl TestDoc {
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<TestCaseResult>
where 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_yaml = extract_yaml_by_key(test_doc_yaml, "test_cases");
let test_cases: TestDocCases<T> = let test_cases: DocCases<T> = DocCases::yaml_decode(&test_cases_yaml.to_string()).unwrap();
TestDocCases::yaml_decode(&test_cases_yaml.to_string()).unwrap();
test_cases.test::<E>() test_cases.test::<E>()
} }

View File

@ -9,11 +9,11 @@ pub use ssz_generic::*;
pub use ssz_static::*; pub use ssz_static::*;
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct TestDocCases<T> { pub struct DocCases<T> {
pub test_cases: Vec<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 /// Decodes a YAML list of test cases
fn yaml_decode(yaml: &String) -> Result<Self, Error> { fn yaml_decode(yaml: &String) -> Result<Self, Error> {
let doc = &YamlLoader::load_from_str(yaml).unwrap()[0]; let doc = &YamlLoader::load_from_str(yaml).unwrap()[0];

View File

@ -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> { fn test<E: EthSpec>(&self) -> Vec<TestCaseResult> {
self.test_cases self.test_cases
.iter() .iter()

View File

@ -41,7 +41,7 @@ impl SszStatic {
} }
} }
impl Test for TestDocCases<SszStatic> { impl Test for DocCases<SszStatic> {
fn test<E: EthSpec>(&self) -> Vec<TestCaseResult> { fn test<E: EthSpec>(&self) -> Vec<TestCaseResult> {
self.test_cases self.test_cases
.iter() .iter()

View File

@ -1,7 +1,7 @@
use super::*; use super::*;
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct TestDocHeader { pub struct DocHeader {
pub title: String, pub title: String,
pub summary: String, pub summary: String,
pub forks_timeline: String, pub forks_timeline: String,

View File

@ -4,18 +4,18 @@ use serde_derive::Deserialize;
use ssz::Decode; use ssz::Decode;
use std::fmt::Debug; 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::error::*;
pub use crate::eth_specs::*; 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; pub use yaml_decode::YamlDecode;
mod case_result;
mod doc;
mod doc_cases;
mod doc_header;
mod error; mod error;
mod eth_specs; mod eth_specs;
mod test_case_result;
mod test_doc;
mod test_doc_cases;
mod test_doc_header;
mod yaml_decode; mod yaml_decode;

View File

@ -21,17 +21,17 @@ mod ssz_generic {
#[test] #[test]
fn uint_bounds() { 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] #[test]
fn uint_random() { 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] #[test]
fn uint_wrong_length() { 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] #[test]
fn minimal_nil() { 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"));
} }
} }