New state tests (#5418)

* General state tests

* Allow dir name for a test
This commit is contained in:
Arkadiy Paronyan
2017-04-12 13:33:49 +02:00
committed by Gav Wood
parent 1b36a381e8
commit 15ae24b541
14 changed files with 328 additions and 868 deletions

View File

@@ -15,21 +15,63 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
pub use util::*;
use std::fs::{File, read_dir};
use std::path::Path;
use std::ffi::OsString;
pub fn run_test_path(p: &Path, skip: &[&'static str], runner: fn (json_data: &[u8]) -> Vec<String>) {
let path = Path::new(p);
let s: HashSet<OsString> = skip.iter().map(|s| {
let mut os: OsString = s.into();
os.push(".json");
os
}).collect();
if path.is_dir() {
for p in read_dir(path).unwrap().filter_map(|e| {
let e = e.unwrap();
if s.contains(&e.file_name()) {
None
} else {
Some(e.path())
}}) {
run_test_path(&p, skip, runner)
}
} else {
let mut path = p.to_path_buf();
path.set_extension("json");
run_test_file(&path, runner)
}
}
pub fn run_test_file(path: &Path, runner: fn (json_data: &[u8]) -> Vec<String>) {
let mut data = Vec::new();
let mut file = File::open(&path).expect("Error opening test file");
file.read_to_end(&mut data).expect("Error reading test file");
let results = runner(&data);
assert!(results.is_empty());
}
macro_rules! test {
($name: expr) => {
assert!(do_json_test(include_bytes!(concat!("../../res/ethereum/tests/", $name, ".json"))).is_empty());
($name: expr, $skip: expr) => {
::json_tests::test_common::run_test_path(::std::path::Path::new(concat!("res/ethereum/tests/", $name)), &$skip, do_json_test);
}
}
#[macro_export]
macro_rules! declare_test {
(skip => $arr: expr, $id: ident, $name: expr) => {
#[test]
#[allow(non_snake_case)]
fn $id() {
test!($name, $arr);
}
};
(ignore => $id: ident, $name: expr) => {
#[ignore]
#[test]
#[allow(non_snake_case)]
fn $id() {
test!($name);
test!($name, []);
}
};
(heavy => $id: ident, $name: expr) => {
@@ -37,14 +79,14 @@ macro_rules! declare_test {
#[test]
#[allow(non_snake_case)]
fn $id() {
test!($name);
test!($name, []);
}
};
($id: ident, $name: expr) => {
#[test]
#[allow(non_snake_case)]
fn $id() {
test!($name);
test!($name, []);
}
}
}