substrate_test_utils/lib.rs
1// This file is part of Substrate.
2
3// Copyright (C) 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/// Panic when the vectors are different, without taking the order into account.
21///
22/// # Examples
23///
24/// ```rust
25/// #[macro_use]
26/// # use substrate_test_utils::{assert_eq_uvec};
27/// # fn main() {
28/// assert_eq_uvec!(vec![1,2], vec![2,1]);
29/// # }
30/// ```
31///
32/// ```rust,should_panic
33/// #[macro_use]
34/// # use substrate_test_utils::{assert_eq_uvec};
35/// # fn main() {
36/// assert_eq_uvec!(vec![1,2,3], vec![2,1]);
37/// # }
38/// ```
39#[macro_export]
40macro_rules! assert_eq_uvec {
41 ( $x:expr, $y:expr $(,)? ) => {
42 $crate::__assert_eq_uvec!($x, $y);
43 $crate::__assert_eq_uvec!($y, $x);
44 };
45}
46
47#[macro_export]
48#[doc(hidden)]
49macro_rules! __assert_eq_uvec {
50 ( $x:expr, $y:expr ) => {
51 $x.iter().for_each(|e| {
52 if !$y.contains(e) {
53 panic!("vectors not equal: {:?} != {:?}", $x, $y);
54 }
55 });
56 };
57}