Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_core/src/macros/test.rs

1.5 KiB, 3 runs

created by r1870400018:106, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1#[macro_export]
2/// A simple test harness. If the given string matches any of the tags, the test is run.
3///
4macro_rules! test_it {
5 ($filter:expr, $name:literal, $($tag:literal),* $(,)? { $($code:tt)* }) => {
6 match $filter {
7 $($tag)|* | $name => {
8 test!("'{}' test...", $name);
9 let _outcome = res! ( Outcome::Ok( { $($code)* } ) );
10 },
11 _ => (),
12 }
13 };
14}
15
16#[macro_export]
17/// A non-panicking `assert_eq` that returns an `Err` when left and right, compared via
18/// `PartialEq`, do not match.
19///
20///```
21/// use oxedyne_fe2o3_core::prelude::*;
22///
23/// fn main() -> Outcome<()> {
24/// let v1 = 42u8;
25/// let v2 = 42u8;
26/// req!(v1, v2); // Will return with an Outcome::Err if not equal
27/// Ok(())
28/// }
29///
30///```
31macro_rules! req {
32 ($left:expr, $right:expr, $($arg:tt)*) => {
33 if $left != $right {
34 return Err(Error::Local(ErrMsg {
35 tags: &[ErrTag::Test, ErrTag::Mismatch],
36 msg: errmsg!(
37 "Left value {:?} does not match right value {:?}: {}",
38 $left, $right, fmt!($($arg)*),
39 ),
40 }));
41 }
42 };
43 ($left:expr, $right:expr $(,)?) => {
44 if $left != $right {
45 return Err(Error::Local(ErrMsg {
46 tags: &[ErrTag::Test, ErrTag::Mismatch],
47 msg: errmsg!("Left value {:?} does not match right value {:?}", $left, $right),
48 }));
49 }
50 }
51}