diff --git a/Cargo.lock b/Cargo.lock index 4e7300c5db011b2bb94e384f2f699dff102c6dd6..b3436f1b58991546d1abe6b5805f242901383147 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -359,13 +359,13 @@ dependencies = [ "dubp-documents-tests-tools 0.1.0", "dup-crypto 0.6.0", "dup-crypto-tests-tools 0.1.0", + "durs-common-tests-tools 0.1.0", "durs-common-tools 0.1.0", "durs-module 0.1.0-a0.1", "durs-wot 0.8.0-a0.9", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "id_tree 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rust-tests-tools 0.1.0", "rustbreak 2.0.0-rc3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.86 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.86 (registry+https://github.com/rust-lang/crates.io-index)", @@ -373,6 +373,14 @@ dependencies = [ "unwrap 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "durs-common-tests-tools" +version = "0.1.0" +dependencies = [ + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "simplelog 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "durs-common-tools" version = "0.1.0" @@ -1187,14 +1195,6 @@ dependencies = [ "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "rust-tests-tools" -version = "0.1.0" -dependencies = [ - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "simplelog 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "rustbreak" version = "2.0.0-rc3" diff --git a/Cargo.toml b/Cargo.toml index 0fec6ffdeaae7c6666cd81fb2e0dabc8dbedda34..c15c5c204603cb3cb5c7f97307a3d9e63fb01b19 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ members = [ "lib/modules/ws2p/ws2p-messages", "lib/tests-tools/crypto-tests-tools", "lib/tests-tools/documents-tests-tools", - "lib/tests-tools/rust-tests-tools", + "lib/tests-tools/common-tests-tools", "lib/tools/crypto", "lib/tools/common-tools", "lib/tools/documents", diff --git a/lib/modules/blockchain/blockchain-dal/Cargo.toml b/lib/modules/blockchain/blockchain-dal/Cargo.toml index 4092ca331c4a24d990f7fdd44dd1bbf0e20f2c56..13d7bf7fe0913bcdd313527d446502e5ab6926bf 100644 --- a/lib/modules/blockchain/blockchain-dal/Cargo.toml +++ b/lib/modules/blockchain/blockchain-dal/Cargo.toml @@ -26,7 +26,7 @@ serde_json = "1.0.*" [dev-dependencies] dup-crypto-tests-tools = { path = "../../../tests-tools/crypto-tests-tools" } dubp-documents-tests-tools = { path = "../../../tests-tools/documents-tests-tools" } -rust-tests-tools = { path = "../../../tests-tools/rust-tests-tools" } +durs-common-tests-tools = { path = "../../../tests-tools/common-tests-tools" } unwrap = "1.2.1" [features] diff --git a/lib/modules/blockchain/blockchain-dal/src/entities/fork_tree.rs b/lib/modules/blockchain/blockchain-dal/src/entities/fork_tree.rs index 51d918024d92f61e6e5ca8b2ea41ba2d19812aec..5264d0b524cbc16fdbf78d32a801ff9b625febf9 100644 --- a/lib/modules/blockchain/blockchain-dal/src/entities/fork_tree.rs +++ b/lib/modules/blockchain/blockchain-dal/src/entities/fork_tree.rs @@ -586,7 +586,7 @@ mod tests { ), (TreeNodeId(11), child_fork_blockstamp), ]; - assert!(rust_tests_tools::collections::slice_same_elems( + assert!(durs_common_tests_tools::collections::slice_same_elems( &expected_sheets, &sheets )); @@ -697,7 +697,7 @@ mod tests { ), ]; println!("{:?}", sheets); - assert!(rust_tests_tools::collections::slice_same_elems( + assert!(durs_common_tests_tools::collections::slice_same_elems( &expected_sheets, &sheets )); @@ -709,7 +709,7 @@ mod tests { ); // Check that the shaft still has 2 same sheets - assert!(rust_tests_tools::collections::slice_same_elems( + assert!(durs_common_tests_tools::collections::slice_same_elems( &expected_sheets, &sheets )); diff --git a/lib/modules/blockchain/blockchain-dal/src/readers/identity.rs b/lib/modules/blockchain/blockchain-dal/src/readers/identity.rs index 4cbbe766a1c369db7eafcb43cf16a39f772cec1d..2ece0d4aa5cbe7bf9d2b552bb9c8797af9bd29ff 100644 --- a/lib/modules/blockchain/blockchain-dal/src/readers/identity.rs +++ b/lib/modules/blockchain/blockchain-dal/src/readers/identity.rs @@ -122,7 +122,7 @@ mod test { use crate::*; use dubp_documents::Blockstamp; use dup_crypto_tests_tools::mocks::pubkey; - use rust_tests_tools::collections::slice_same_elems; + use durs_common_tests_tools::collections::slice_same_elems; fn gen_mock_dal_idty(pubkey: PubKey, created_block_id: BlockNumber) -> DALIdentity { DALIdentity { diff --git a/lib/modules/blockchain/blockchain-dal/src/writers/fork_tree.rs b/lib/modules/blockchain/blockchain-dal/src/writers/fork_tree.rs index b4bd8d6df2ea1593d962ce8c5bf94976acc14d0b..a4e702fe66cbff395e0c36b38f58dbf430087e7a 100644 --- a/lib/modules/blockchain/blockchain-dal/src/writers/fork_tree.rs +++ b/lib/modules/blockchain/blockchain-dal/src/writers/fork_tree.rs @@ -187,7 +187,7 @@ mod test { // Check tree state assert_eq!(5, fork_tree_db.read(|tree| tree.size())?); - assert!(rust_tests_tools::collections::slice_same_elems( + assert!(durs_common_tests_tools::collections::slice_same_elems( &vec![ (TreeNodeId(3), blockstamps[3]), (TreeNodeId(4), fork_blockstamp) @@ -207,7 +207,7 @@ mod test { // Check tree state assert_eq!(6, fork_tree_db.read(|tree| tree.size())?); - assert!(rust_tests_tools::collections::slice_same_elems( + assert!(durs_common_tests_tools::collections::slice_same_elems( &vec![ (TreeNodeId(3), blockstamps[3]), (TreeNodeId(5), fork_blockstamp_2) @@ -228,7 +228,7 @@ mod test { *crate::constants::FORK_WINDOW_SIZE + 2, fork_tree_db.read(|tree| tree.size())? ); - assert!(rust_tests_tools::collections::slice_same_elems( + assert!(durs_common_tests_tools::collections::slice_same_elems( &vec![ ( TreeNodeId(*crate::constants::FORK_WINDOW_SIZE + 1), diff --git a/lib/tests-tools/rust-tests-tools/Cargo.toml b/lib/tests-tools/common-tests-tools/Cargo.toml similarity index 69% rename from lib/tests-tools/rust-tests-tools/Cargo.toml rename to lib/tests-tools/common-tests-tools/Cargo.toml index 88df693933621cfcf1d954e560ef23fa4659f571..a721418b1e700f29153bb9860295b86ecc75dd8a 100644 --- a/lib/tests-tools/rust-tests-tools/Cargo.toml +++ b/lib/tests-tools/common-tests-tools/Cargo.toml @@ -1,11 +1,11 @@ [package] -name = "rust-tests-tools" +name = "durs-common-tests-tools" version = "0.1.0" authors = ["elois <elois@duniter.org>"] -description = "Common tests tools for rust projects." +description = "Common tests tools for Durs project." repository = "https://git.duniter.org/nodes/rust/duniter-rs" readme = "README.md" -keywords = ["rust", "test", "tools"] +keywords = ["durs", "test", "tools"] license = "AGPL-3.0" edition = "2018" diff --git a/lib/tests-tools/rust-tests-tools/src/collections/mod.rs b/lib/tests-tools/common-tests-tools/src/collections/mod.rs similarity index 97% rename from lib/tests-tools/rust-tests-tools/src/collections/mod.rs rename to lib/tests-tools/common-tests-tools/src/collections/mod.rs index 655369e43d24d50318476a443b791cd2d82d0882..662896d516c5b1f63e1a31c1a3c498efb33dd6f9 100644 --- a/lib/tests-tools/rust-tests-tools/src/collections/mod.rs +++ b/lib/tests-tools/common-tests-tools/src/collections/mod.rs @@ -1,4 +1,4 @@ -// Copyright (C) 2019 Éloïs SANCHEZ +// Copyright (C) 2018 The Durs Project Developers. // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as diff --git a/lib/tests-tools/rust-tests-tools/src/lib.rs b/lib/tests-tools/common-tests-tools/src/lib.rs similarity index 62% rename from lib/tests-tools/rust-tests-tools/src/lib.rs rename to lib/tests-tools/common-tests-tools/src/lib.rs index 9223435505a5cf4bf86ea994ab27cc1d9acedc50..9449e5c1676da00eabd7524c6b2649279436d81f 100644 --- a/lib/tests-tools/rust-tests-tools/src/lib.rs +++ b/lib/tests-tools/common-tests-tools/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright (C) 2019 Éloïs SANCHEZ +// Copyright (C) 2018 The Durs Project Developers. // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -27,22 +27,4 @@ )] pub mod collections; - -use log::Level; -use simplelog::{Config, LevelFilter, TermLogger}; - -/// Initialize simple stdout logger -pub fn init_logger_stdout() { - // Config logger - let logger_config = Config { - time: Some(Level::Error), - level: Some(Level::Error), - target: Some(Level::Debug), - location: Some(Level::Debug), - time_format: Some("%Y-%m-%d %H:%M:%S%:z"), - }; - - // Active stdout logger - TermLogger::init(LevelFilter::Debug, logger_config) - .expect("TESTS: fail to init stdout logger !"); -} +pub mod logger; diff --git a/lib/tests-tools/common-tests-tools/src/logger.rs b/lib/tests-tools/common-tests-tools/src/logger.rs new file mode 100644 index 0000000000000000000000000000000000000000..201e2722d3f9d4155c1d1f62af1ea7f7389eee3f --- /dev/null +++ b/lib/tests-tools/common-tests-tools/src/logger.rs @@ -0,0 +1,67 @@ +// Copyright (C) 2018 The Durs Project Developers. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program 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 Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +//! Common test tools for DURS project. + +use log::Level; +use simplelog::{Config, LevelFilter, SimpleLogger, TermLogger}; + +/// Initialize simple stdout logger +pub fn init_logger_stdout() { + let colors = match std::env::var("DURS_TESTS_LOG_COLOR") + .unwrap_or_else(|_| String::from("no")) + .as_str() + { + "yes" => true, + "no" => false, + v => panic!( + "Unexpected value '{}' for env var DURS_TESTS_LOG_COLOR !", + v + ), + }; + + let level_filter = match std::env::var("DURS_TESTS_LOG_LEVEL") + .unwrap_or_else(|_| String::from("debug")) + .as_str() + { + "off" => LevelFilter::Off, + "error" => LevelFilter::Error, + "warn" => LevelFilter::Warn, + "info" => LevelFilter::Info, + "debug" => LevelFilter::Debug, + "trace" => LevelFilter::Trace, + v => panic!( + "Unexpected value '{}' for env var DURS_TESTS_LOG_LEVEL !", + v + ), + }; + + // Config logger + let logger_config = Config { + time: Some(Level::Error), + level: Some(Level::Error), + target: Some(Level::Debug), + location: Some(Level::Debug), + time_format: Some("%Y-%m-%d %H:%M:%S%:z"), + }; + + // Active stdout logger + if colors { + TermLogger::init(level_filter, logger_config).expect("TESTS: fail to init stdout logger !"); + } else { + SimpleLogger::init(level_filter, logger_config) + .expect("TESTS: fail to init stdout logger !"); + } +}