Remove substrate_test_utils::test (#1321)

* Directly use tokio::test

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove old code

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Delete substrate-test-utils-test-crate

Also not needed anymore.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
Oliver Tale-Yazdi
2023-08-31 12:48:39 +02:00
committed by GitHub
parent 80a19bec6a
commit dfc0d1bc83
17 changed files with 5 additions and 283 deletions
Generated
-20
View File
@@ -18321,30 +18321,10 @@ version = "4.0.0-dev"
dependencies = [
"futures",
"sc-service",
"substrate-test-utils-derive",
"tokio",
"trybuild",
]
[[package]]
name = "substrate-test-utils-derive"
version = "0.10.0-dev"
dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
"syn 2.0.29",
]
[[package]]
name = "substrate-test-utils-test-crate"
version = "0.1.0"
dependencies = [
"sc-service",
"substrate-test-utils",
"tokio",
]
[[package]]
name = "substrate-wasm-builder"
version = "5.0.0-dev"
-2
View File
@@ -432,11 +432,9 @@ members = [
"substrate/test-utils",
"substrate/test-utils/cli",
"substrate/test-utils/client",
"substrate/test-utils/derive",
"substrate/test-utils/runtime",
"substrate/test-utils/runtime/client",
"substrate/test-utils/runtime/transaction-pool",
"substrate/test-utils/test-crate",
"substrate/utils/binary-merkle-tree",
"substrate/utils/build-script-utils",
"substrate/utils/fork-tree",
+1 -1
View File
@@ -24,7 +24,7 @@ use std::collections::HashMap;
const DEFAULT_PROMETHEUS_PORT: u16 = 9616;
#[substrate_test_utils::test(flavor = "multi_thread")]
#[tokio::test(flavor = "multi_thread")]
async fn runtime_can_publish_metrics() {
let mut alice_config =
node_config(|| {}, tokio::runtime::Handle::current(), Alice, Vec::new(), true);
@@ -18,7 +18,7 @@ use futures::{future, pin_mut, select, FutureExt};
use polkadot_test_service::*;
use sp_keyring::Sr25519Keyring;
#[substrate_test_utils::test(flavor = "multi_thread")]
#[tokio::test(flavor = "multi_thread")]
async fn ensure_test_service_build_blocks() {
let mut builder = sc_cli::LoggerBuilder::new("");
builder.with_colors(false);
@@ -17,7 +17,7 @@
use polkadot_test_service::*;
use sp_keyring::Sr25519Keyring::{Alice, Bob, Charlie};
#[substrate_test_utils::test(flavor = "multi_thread")]
#[tokio::test(flavor = "multi_thread")]
async fn call_function_actually_work() {
let alice_config =
node_config(|| {}, tokio::runtime::Handle::current(), Alice, Vec::new(), true);
@@ -22,7 +22,7 @@ const PUPPET_EXE: &str = env!("CARGO_BIN_EXE_adder_collator_puppet_worker");
// If this test is failing, make sure to run all tests with the `real-overseer` feature being
// enabled.
#[substrate_test_utils::test(flavor = "multi_thread")]
#[tokio::test(flavor = "multi_thread")]
async fn collating_using_adder_collator() {
use polkadot_primitives::Id as ParaId;
use sp_keyring::AccountKeyring::*;
@@ -21,7 +21,7 @@ const PUPPET_EXE: &str = env!("CARGO_BIN_EXE_undying_collator_puppet_worker");
// If this test is failing, make sure to run all tests with the `real-overseer` feature being
// enabled.
#[substrate_test_utils::test(flavor = "multi_thread")]
#[tokio::test(flavor = "multi_thread")]
async fn collating_using_undying_collator() {
use polkadot_primitives::Id as ParaId;
use sp_keyring::AccountKeyring::*;
-1
View File
@@ -15,7 +15,6 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
futures = "0.3.16"
tokio = { version = "1.22.0", features = ["macros", "time"] }
substrate-test-utils-derive = { path = "derive" }
[dev-dependencies]
trybuild = { version = "1.0.74", features = [ "diff" ] }
-19
View File
@@ -1,19 +0,0 @@
[package]
name = "substrate-test-utils-derive"
version = "0.10.0-dev"
authors.workspace = true
edition.workspace = true
license = "Apache-2.0"
homepage = "https://substrate.io"
repository.workspace = true
description = "Substrate test utilities macros"
publish = false
[dependencies]
proc-macro-crate = "1.1.3"
proc-macro2 = "1.0.56"
quote = "1.0.28"
syn = { version = "2.0.16", features = ["full"] }
[lib]
proc-macro = true
-73
View File
@@ -1,73 +0,0 @@
// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program 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.
// 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 General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use proc_macro::{Span, TokenStream};
use proc_macro_crate::{crate_name, FoundCrate};
use quote::quote;
#[proc_macro_attribute]
pub fn test(args: TokenStream, item: TokenStream) -> TokenStream {
let input = syn::parse_macro_input!(item as syn::ItemFn);
parse_knobs(input, args.into()).unwrap_or_else(|e| e.to_compile_error().into())
}
fn parse_knobs(
mut input: syn::ItemFn,
args: proc_macro2::TokenStream,
) -> Result<TokenStream, syn::Error> {
let sig = &mut input.sig;
let body = &input.block;
let attrs = &input.attrs;
let vis = input.vis;
if !sig.inputs.is_empty() {
return Err(syn::Error::new_spanned(&sig, "No arguments expected for tests."))
}
let crate_name = match crate_name("substrate-test-utils") {
Ok(FoundCrate::Itself) => syn::Ident::new("substrate_test_utils", Span::call_site().into()),
Ok(FoundCrate::Name(crate_name)) => syn::Ident::new(&crate_name, Span::call_site().into()),
Err(e) => return Err(syn::Error::new_spanned(&sig, e)),
};
let header = {
quote! {
#[#crate_name::tokio::test( #args )]
}
};
let result = quote! {
#header
#(#attrs)*
#vis #sig {
if #crate_name::tokio::time::timeout(
std::time::Duration::from_secs(
std::env::var("SUBSTRATE_TEST_TIMEOUT")
.ok()
.and_then(|x| x.parse().ok())
.unwrap_or(600)),
async move { #body },
).await.is_err() {
panic!("The test took too long!");
}
}
};
Ok(result.into())
}
-20
View File
@@ -17,26 +17,6 @@
//! Test utils
#[doc(hidden)]
pub use futures;
/// Marks async function to be executed by an async runtime suitable to test environment.
///
/// # Requirements
///
/// You must have tokio in the `[dev-dependencies]` of your crate to use this macro.
///
/// # Example
///
/// ```
/// #[substrate_test_utils::test]
/// async fn basic_test() {
/// assert!(true);
/// }
/// ```
pub use substrate_test_utils_derive::test;
#[doc(hidden)]
pub use tokio;
/// Panic when the vectors are different, without taking the order into account.
///
/// # Examples
@@ -1,17 +0,0 @@
[package]
name = "substrate-test-utils-test-crate"
version = "0.1.0"
authors.workspace = true
edition.workspace = true
license = "Apache-2.0"
homepage = "https://substrate.io"
repository.workspace = true
publish = false
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
[dev-dependencies]
tokio = { version = "1.22.0", features = ["macros"] }
sc-service = { path = "../../client/service" }
test-utils = { package = "substrate-test-utils", path = ".." }
@@ -1,25 +0,0 @@
// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program 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.
// 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 General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#[cfg(test)]
#[test_utils::test]
async fn basic_test() {
assert!(true);
}
fn main() {}
-49
View File
@@ -1,49 +0,0 @@
// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program 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.
// 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 General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#[substrate_test_utils::test]
async fn basic_test() {
assert!(true);
}
#[substrate_test_utils::test]
#[should_panic(expected = "boo!")]
async fn panicking_test() {
panic!("boo!");
}
#[substrate_test_utils::test(flavor = "multi_thread", worker_threads = 1)]
async fn basic_test_with_args() {
assert!(true);
}
// NOTE: enable this test only after setting SUBSTRATE_TEST_TIMEOUT to a smaller value
//
// SUBSTRATE_TEST_TIMEOUT=1 cargo test -- --ignored timeout
#[substrate_test_utils::test]
#[should_panic(expected = "test took too long")]
#[ignore]
async fn timeout() {
tokio::time::sleep(std::time::Duration::from_secs(
std::env::var("SUBSTRATE_TEST_TIMEOUT")
.expect("env var SUBSTRATE_TEST_TIMEOUT has been provided by the user")
.parse::<u64>()
.unwrap() + 1,
))
.await;
}
-23
View File
@@ -1,23 +0,0 @@
// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program 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.
// 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 General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#[test]
fn substrate_test_utils_derive_trybuild() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/ui/too-many-func-parameters.rs");
}
@@ -1,24 +0,0 @@
// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program 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.
// 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 General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#[substrate_test_utils::test]
async fn too_many_func_parameters(_: u32) {
assert!(true);
}
fn main() {}
@@ -1,5 +0,0 @@
error: No arguments expected for tests.
--> $DIR/too-many-func-parameters.rs:20:1
|
20 | async fn too_many_func_parameters(_: u32) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^