[dependencies]: remove util/macros (#11501)

* [dependencies]: remove `util/macros`

* fix typo: `flish` -> flush`

* [json tests]: add log if `write` or `flush` fails

`write` is performed to `stdout`
`logging` is performed to `stderr`

* [rocksdb-migration]: remove unused `Progress`

* [rpc test]: BTreeMap -> `btreemap!`
This commit is contained in:
Niklas Adolfsson
2020-02-19 13:07:33 +01:00
committed by GitHub
parent 70f08e1549
commit a49950e9c0
41 changed files with 296 additions and 434 deletions

View File

@@ -25,8 +25,7 @@ use io::IoChannel;
use test_helpers::{self, EvmTestClient};
use types::verification::Unverified;
use verification::{VerifierType, queue::kind::BlockLike};
use super::SKIP_TESTS;
use super::HookType;
use super::{HookType, SKIP_TESTS};
#[allow(dead_code)]
fn skip_test(name: &String) -> bool {
@@ -56,7 +55,7 @@ pub fn json_chain_test<H: FnMut(&str, HookType)>(path: &Path, json_data: &[u8],
let mut fail_unless = |cond: bool| {
if !cond && !fail {
failed.push(name.clone());
flushln!("FAIL");
flushed_writeln!("FAIL");
fail = true;
true
} else {
@@ -64,7 +63,7 @@ pub fn json_chain_test<H: FnMut(&str, HookType)>(path: &Path, json_data: &[u8],
}
};
flush!(" - {}...", name);
flushed_write!(" - {}...", name);
let spec = {
let mut spec = match EvmTestClient::fork_spec_from_json(&blockchain.network) {
@@ -123,9 +122,9 @@ pub fn json_chain_test<H: FnMut(&str, HookType)>(path: &Path, json_data: &[u8],
}
if !fail {
flushln!("ok");
flushed_writeln!("OK");
} else {
flushln!("fail");
flushed_writeln!("FAILED");
}
start_stop_hook(&name, HookType::OnStop);

View File

@@ -37,8 +37,7 @@ pub fn json_difficulty_test<H: FnMut(&str, HookType)>(
for (name, test) in tests.into_iter() {
start_stop_hook(&name, HookType::OnStart);
flush!(" - {}...", name);
println!(" - {}...", name);
flushed_writeln!(" - {}...", name);
let mut parent_header = Header::new();
let block_number: u64 = test.current_block_number.into();
@@ -53,7 +52,7 @@ pub fn json_difficulty_test<H: FnMut(&str, HookType)>(
engine.populate_from_parent(&mut header, &parent_header);
let expected_difficulty: U256 = test.current_difficulty.into();
assert_eq!(header.difficulty(), &expected_difficulty);
flushln!("ok");
flushed_writeln!("OK");
start_stop_hook(&name, HookType::OnStop);
}

View File

@@ -0,0 +1,86 @@
//! Helper macros for running the `JSON tests`
/// Declares a test:
///
/// declare_test!(test_name, "path/to/folder/with/tests");
///
/// Declares a test but skip the named test files inside the folder (no extension):
///
/// declare_test!(skip => ["a-test-file", "other-test-file"], test_name, "path/to/folder/with/tests");
///
/// NOTE: a skipped test is considered a passing test as far as `cargo test` is concerned. Normally
/// one test corresponds to a folder full of test files, each of which may contain many tests.
#[macro_export]
macro_rules! declare_test {
(skip => $arr: expr, $id: ident, $name: expr) => {
#[cfg(test)]
#[test]
#[allow(non_snake_case)]
fn $id() {
test!($name, $arr);
}
};
(ignore => $id: ident, $name: expr) => {
#[cfg(test)]
#[ignore]
#[test]
#[allow(non_snake_case)]
fn $id() {
test!($name, []);
}
};
(heavy => $id: ident, $name: expr) => {
#[cfg(test)]
#[cfg(feature = "test-heavy")]
#[test]
#[allow(non_snake_case)]
fn $id() {
test!($name, []);
}
};
($id: ident, $name: expr) => {
#[cfg(test)]
#[test]
#[allow(non_snake_case)]
fn $id() {
test!($name, []);
}
}
}
#[cfg(test)]
macro_rules! test {
($name: expr, $skip: expr) => {
$crate::json_tests::test_common::run_test_path(
std::path::Path::new(concat!("res/ethereum/tests/", $name)),
&$skip,
do_json_test,
&mut |_, _| ()
);
}
}
/// Similar to `print!` but flushes stdout in order to ensure the output is emitted immediately.
#[macro_export]
macro_rules! flushed_write {
($arg:expr) => ($crate::json_tests::macros::write_and_flush($arg.into()));
($($arg:tt)*) => ($crate::json_tests::macros::write_and_flush(format!("{}", format_args!($($arg)*))));
}
/// Similar to `println!` but flushes stdout in order to ensure the output is emitted immediately.
#[macro_export]
macro_rules! flushed_writeln {
($fmt:expr) => (flushed_write!(concat!($fmt, "\n")));
($fmt:expr, $($arg:tt)*) => (flushed_write!(concat!($fmt, "\n"), $($arg)*));
}
/// Write to stdout and flush (ignores errors)
#[doc(hidden)]
pub fn write_and_flush(s: String) {
if let Err(err) = std::io::Write::write_all(&mut std::io::stdout(), s.as_bytes()) {
error!(target: "json_tests", "io::Write::write_all to stdout failed because of: {:?}", err);
}
if let Err(err) = std::io::Write::flush(&mut std::io::stdout()) {
error!(target: "json_tests", "io::Write::flush stdout failed because of: {:?}", err);
}
}

View File

@@ -14,23 +14,24 @@
// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
//! Helpers and tests for operating on jsontests.
//! Helpers and tests for operating on `JSON` tests.
#[macro_use]
mod test_common;
mod macros;
mod transaction;
mod executive;
mod state;
mod chain;
mod trie;
mod executive;
mod skip;
mod state;
mod test_common;
mod transaction;
mod trie;
#[cfg(test)]
mod difficulty;
pub use self::test_common::HookType;
pub use self::executive::run_test_path as run_executive_test_path;
pub use self::executive::run_test_file as run_executive_test_file;
pub use self::test_common::HookType;
use self::skip::SKIP_TESTS;

View File

@@ -17,13 +17,10 @@
use std::path::Path;
use super::test_common::*;
use pod::PodState;
use trace;
use ethjson;
use test_helpers::{EvmTestClient, EvmTestError, TransactErr, TransactSuccess};
use types::transaction::SignedTransaction;
use vm::EnvInfo;
use super::SKIP_TESTS;
use super::HookType;
#[allow(dead_code)]
fn skip_test(subname: &str, chain: &String, number: usize) -> bool {
@@ -84,25 +81,25 @@ pub fn json_chain_test<H: FnMut(&str, HookType)>(path: &Path, json_data: &[u8],
match result() {
Err(err) => {
println!("{} !!! Unexpected internal error: {:?}", info, err);
flushln!("{} fail", info);
flushed_writeln!("{} fail", info);
failed.push(name.clone());
},
Ok(Ok(TransactSuccess { state_root, .. })) if state_root != post_root => {
println!("{} !!! State mismatch (got: {}, expect: {}", info, state_root, post_root);
flushln!("{} fail", info);
flushed_writeln!("{} fail", info);
failed.push(name.clone());
},
Ok(Err(TransactErr { state_root, ref error, .. })) if state_root != post_root => {
println!("{} !!! State mismatch (got: {}, expect: {}", info, state_root, post_root);
println!("{} !!! Execution error: {:?}", info, error);
flushln!("{} fail", info);
flushed_writeln!("{} fail", info);
failed.push(name.clone());
},
Ok(Err(TransactErr { error, .. })) => {
flushln!("{} ok ({:?})", info, error);
flushed_writeln!("{} ok ({:?})", info, error);
},
Ok(_) => {
flushln!("{} ok", info);
flushed_writeln!("{} ok", info);
},
}
}

View File

@@ -19,6 +19,7 @@ use std::io::Read;
use std::fs::{File, read_dir};
use std::path::Path;
use std::ffi::OsString;
pub use ethereum_types::{H256, U256, Address};
/// Indicate when to run the hook passed to test functions.
@@ -41,7 +42,7 @@ pub fn run_test_path<H: FnMut(&str, HookType)>(
if !skip.is_empty() {
// todo[dvdplm] it's really annoying to have to use flushln here. Should be `info!(target:
// "json-tests", …)`. Issue https://github.com/paritytech/parity-ethereum/issues/11084
flushln!("[run_test_path] Skipping tests in {}: {:?}", path.display(), skip);
flushed_writeln!("[run_test_path] Skipping tests in {}: {:?}", path.display(), skip);
}
let mut errors = Vec::new();
run_test_path_inner(path, skip, runner, start_stop_hook, &mut errors);
@@ -121,63 +122,3 @@ pub fn run_test_file<H: FnMut(&str, HookType)>(
let empty: [String; 0] = [];
assert_eq!(results, empty);
}
#[cfg(test)]
macro_rules! test {
($name: expr, $skip: expr) => {
::json_tests::test_common::run_test_path(
::std::path::Path::new(concat!("res/ethereum/tests/", $name)),
&$skip,
do_json_test,
&mut |_, _| ()
);
}
}
/// Declares a test:
///
/// declare_test!(test_name, "path/to/folder/with/tests");
///
/// Declares a test but skip the named test files inside the folder (no extension):
///
/// declare_test!(skip => ["a-test-file", "other-test-file"], test_name, "path/to/folder/with/tests");
///
/// NOTE: a skipped test is considered a passing test as far as `cargo test` is concerned. Normally
/// one test corresponds to a folder full of test files, each of which may contain many tests.
#[macro_export]
macro_rules! declare_test {
(skip => $arr: expr, $id: ident, $name: expr) => {
#[cfg(test)]
#[test]
#[allow(non_snake_case)]
fn $id() {
test!($name, $arr);
}
};
(ignore => $id: ident, $name: expr) => {
#[cfg(test)]
#[ignore]
#[test]
#[allow(non_snake_case)]
fn $id() {
test!($name, []);
}
};
(heavy => $id: ident, $name: expr) => {
#[cfg(test)]
#[cfg(feature = "test-heavy")]
#[test]
#[allow(non_snake_case)]
fn $id() {
test!($name, []);
}
};
($id: ident, $name: expr) => {
#[cfg(test)]
#[test]
#[allow(non_snake_case)]
fn $id() {
test!($name, []);
}
}
}