Update test_harness clap args structure
Prepares it for adding a new subcommand
This commit is contained in:
parent
f479beb87e
commit
9a964be58b
@ -1,10 +1,9 @@
|
|||||||
use clap::{App, Arg};
|
use clap::{App, Arg, SubCommand};
|
||||||
use env_logger::{Builder, Env};
|
use env_logger::{Builder, Env};
|
||||||
use std::{fs::File, io::prelude::*};
|
use run_test::run_test;
|
||||||
use test_case::TestCase;
|
|
||||||
use yaml_rust::YamlLoader;
|
|
||||||
|
|
||||||
mod beacon_chain_harness;
|
mod beacon_chain_harness;
|
||||||
|
mod run_test;
|
||||||
mod test_case;
|
mod test_case;
|
||||||
mod validator_harness;
|
mod validator_harness;
|
||||||
|
|
||||||
@ -15,13 +14,6 @@ fn main() {
|
|||||||
.version("0.0.1")
|
.version("0.0.1")
|
||||||
.author("Sigma Prime <contact@sigmaprime.io>")
|
.author("Sigma Prime <contact@sigmaprime.io>")
|
||||||
.about("Runs `test_harness` using a YAML test_case.")
|
.about("Runs `test_harness` using a YAML test_case.")
|
||||||
.arg(
|
|
||||||
Arg::with_name("yaml")
|
|
||||||
.long("yaml")
|
|
||||||
.value_name("FILE")
|
|
||||||
.help("YAML file test_case.")
|
|
||||||
.required(true),
|
|
||||||
)
|
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("log")
|
Arg::with_name("log")
|
||||||
.long("log-level")
|
.long("log-level")
|
||||||
@ -31,39 +23,24 @@ fn main() {
|
|||||||
.default_value("debug")
|
.default_value("debug")
|
||||||
.required(true),
|
.required(true),
|
||||||
)
|
)
|
||||||
|
.subcommand(
|
||||||
|
SubCommand::with_name("run_test")
|
||||||
|
.about("Executes a YAML test specification")
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("yaml")
|
||||||
|
.long("yaml")
|
||||||
|
.value_name("FILE")
|
||||||
|
.help("YAML file test_case.")
|
||||||
|
.required(true),
|
||||||
|
),
|
||||||
|
)
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
if let Some(log_level) = matches.value_of("log") {
|
if let Some(log_level) = matches.value_of("log") {
|
||||||
Builder::from_env(Env::default().default_filter_or(log_level)).init();
|
Builder::from_env(Env::default().default_filter_or(log_level)).init();
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(yaml_file) = matches.value_of("yaml") {
|
if let Some(matches) = matches.subcommand_matches("run_test") {
|
||||||
let docs = {
|
run_test(matches);
|
||||||
let mut file = File::open(yaml_file).unwrap();
|
|
||||||
|
|
||||||
let mut yaml_str = String::new();
|
|
||||||
file.read_to_string(&mut yaml_str).unwrap();
|
|
||||||
|
|
||||||
YamlLoader::load_from_str(&yaml_str).unwrap()
|
|
||||||
};
|
|
||||||
|
|
||||||
for doc in &docs {
|
|
||||||
// For each `test_cases` YAML in the document, build a `TestCase`, execute it and
|
|
||||||
// assert that the execution result matches the test_case description.
|
|
||||||
//
|
|
||||||
// In effect, for each `test_case` a new `BeaconChainHarness` is created from genesis
|
|
||||||
// and a new `BeaconChain` is built as per the test_case.
|
|
||||||
//
|
|
||||||
// After the `BeaconChain` has been built out as per the test_case, a dump of all blocks
|
|
||||||
// and states in the chain is obtained and checked against the `results` specified in
|
|
||||||
// the `test_case`.
|
|
||||||
//
|
|
||||||
// If any of the expectations in the results are not met, the process
|
|
||||||
// panics with a message.
|
|
||||||
for test_case in doc["test_cases"].as_vec().unwrap() {
|
|
||||||
let test_case = TestCase::from_yaml(test_case);
|
|
||||||
test_case.assert_result_valid(test_case.execute())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
36
beacon_node/beacon_chain/test_harness/src/run_test.rs
Normal file
36
beacon_node/beacon_chain/test_harness/src/run_test.rs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
use crate::test_case::TestCase;
|
||||||
|
use clap::ArgMatches;
|
||||||
|
use std::{fs::File, io::prelude::*};
|
||||||
|
use yaml_rust::YamlLoader;
|
||||||
|
|
||||||
|
pub fn run_test(matches: &ArgMatches) {
|
||||||
|
if let Some(yaml_file) = matches.value_of("yaml") {
|
||||||
|
let docs = {
|
||||||
|
let mut file = File::open(yaml_file).unwrap();
|
||||||
|
|
||||||
|
let mut yaml_str = String::new();
|
||||||
|
file.read_to_string(&mut yaml_str).unwrap();
|
||||||
|
|
||||||
|
YamlLoader::load_from_str(&yaml_str).unwrap()
|
||||||
|
};
|
||||||
|
|
||||||
|
for doc in &docs {
|
||||||
|
// For each `test_cases` YAML in the document, build a `TestCase`, execute it and
|
||||||
|
// assert that the execution result matches the test_case description.
|
||||||
|
//
|
||||||
|
// In effect, for each `test_case` a new `BeaconChainHarness` is created from genesis
|
||||||
|
// and a new `BeaconChain` is built as per the test_case.
|
||||||
|
//
|
||||||
|
// After the `BeaconChain` has been built out as per the test_case, a dump of all blocks
|
||||||
|
// and states in the chain is obtained and checked against the `results` specified in
|
||||||
|
// the `test_case`.
|
||||||
|
//
|
||||||
|
// If any of the expectations in the results are not met, the process
|
||||||
|
// panics with a message.
|
||||||
|
for test_case in doc["test_cases"].as_vec().unwrap() {
|
||||||
|
let test_case = TestCase::from_yaml(test_case);
|
||||||
|
test_case.assert_result_valid(test_case.execute())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user