2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2016-02-05 13:40:41 +01:00
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-10-24 18:35:25 +02:00
|
|
|
pub use util::*;
|
2017-07-29 23:19:33 +02:00
|
|
|
use std::collections::HashSet;
|
|
|
|
use std::io::Read;
|
2017-04-12 13:33:49 +02:00
|
|
|
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());
|
|
|
|
}
|
2016-01-12 16:20:29 +01:00
|
|
|
|
2016-01-21 16:08:09 +01:00
|
|
|
macro_rules! test {
|
2017-04-12 13:33:49 +02:00
|
|
|
($name: expr, $skip: expr) => {
|
|
|
|
::json_tests::test_common::run_test_path(::std::path::Path::new(concat!("res/ethereum/tests/", $name)), &$skip, do_json_test);
|
2016-01-21 16:08:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-12 16:20:29 +01:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! declare_test {
|
2017-04-12 13:33:49 +02:00
|
|
|
(skip => $arr: expr, $id: ident, $name: expr) => {
|
|
|
|
#[test]
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
fn $id() {
|
|
|
|
test!($name, $arr);
|
|
|
|
}
|
|
|
|
};
|
2016-01-21 16:08:09 +01:00
|
|
|
(ignore => $id: ident, $name: expr) => {
|
|
|
|
#[ignore]
|
2016-01-12 16:20:29 +01:00
|
|
|
#[test]
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
fn $id() {
|
2017-04-12 13:33:49 +02:00
|
|
|
test!($name, []);
|
2016-01-12 16:20:29 +01:00
|
|
|
}
|
|
|
|
};
|
2016-01-21 16:08:09 +01:00
|
|
|
(heavy => $id: ident, $name: expr) => {
|
|
|
|
#[cfg(feature = "test-heavy")]
|
2016-01-12 16:20:29 +01:00
|
|
|
#[test]
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
fn $id() {
|
2017-04-12 13:33:49 +02:00
|
|
|
test!($name, []);
|
2016-01-12 16:20:29 +01:00
|
|
|
}
|
|
|
|
};
|
2016-01-21 16:08:09 +01:00
|
|
|
($id: ident, $name: expr) => {
|
|
|
|
#[test]
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
fn $id() {
|
2017-04-12 13:33:49 +02:00
|
|
|
test!($name, []);
|
2016-01-21 16:08:09 +01:00
|
|
|
}
|
|
|
|
}
|
2016-01-12 16:20:29 +01:00
|
|
|
}
|