substrate_test_utils/
lib.rs

1// This file is part of Substrate.
2
3// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18//! Test utils
19
20#[doc(hidden)]
21pub use futures;
22/// Marks async function to be executed by an async runtime and provide a `TaskExecutor`, suitable
23/// to test environment.
24///
25/// # Requirements
26///
27///	You must have tokio in the `[dev-dependencies]` of your crate to use this macro.
28///
29/// # Example
30///
31/// ```
32/// #[substrate_test_utils::test]
33/// async fn basic_test(task_executor: TaskExecutor) {
34///     assert!(true);
35///     // create your node in here and use task_executor
36///     // then don't forget to gracefully shutdown your node before exit
37/// }
38/// ```
39pub use substrate_test_utils_derive::test;
40#[doc(hidden)]
41pub use tokio;
42
43/// Panic when the vectors are different, without taking the order into account.
44///
45/// # Examples
46///
47/// ```rust
48/// #[macro_use]
49/// # use substrate_test_utils::{assert_eq_uvec};
50/// # fn main() {
51/// assert_eq_uvec!(vec![1,2], vec![2,1]);
52/// # }
53/// ```
54///
55/// ```rust,should_panic
56/// #[macro_use]
57/// # use substrate_test_utils::{assert_eq_uvec};
58/// # fn main() {
59/// assert_eq_uvec!(vec![1,2,3], vec![2,1]);
60/// # }
61/// ```
62#[macro_export]
63macro_rules! assert_eq_uvec {
64	( $x:expr, $y:expr $(,)? ) => {
65		$crate::__assert_eq_uvec!($x, $y);
66		$crate::__assert_eq_uvec!($y, $x);
67	}
68}
69
70#[macro_export]
71#[doc(hidden)]
72macro_rules! __assert_eq_uvec {
73	( $x:expr, $y:expr ) => {
74		$x.iter().for_each(|e| {
75			if !$y.contains(e) { panic!(format!("vectors not equal: {:?} != {:?}", $x, $y)); }
76		});
77	}
78}