mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
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:
committed by
GitHub
parent
80a19bec6a
commit
dfc0d1bc83
@@ -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" ] }
|
||||
|
||||
@@ -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
|
||||
@@ -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())
|
||||
}
|
||||
@@ -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() {}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
Reference in New Issue
Block a user