Macro assertables::assert_fn_ge_expr
source · macro_rules! assert_fn_ge_expr { ($a_function:path, $a_param:expr, $b_expr:expr $(,)?) => { ... }; ($a_function:path, $a_param:expr, $b_expr:expr, $($message:tt)+) => { ... }; ($a_function:path, $b_expr:expr $(,)?) => { ... }; ($a_function:path, $b_expr:expr, $($message:tt)+) => { ... }; }
Expand description
Assert a function output is greater than or equal to an expression.
-
If true, return
(). -
Otherwise, call
panic!with a message and the values of the expressions with their debug representations.
§Examples
// Return Ok
let a: i8 = -2;
let b: i8 = 1;
assert_fn_ge_expr!(i8::abs, a, b);
//-> ()
// Panic with error message
let result = panic::catch_unwind(|| {
let a: i8 = -1;
let b: i8 = 2;
assert_fn_ge_expr!(i8::abs, a, b);
//-> panic!
});
assert!(result.is_err());
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = concat!(
"assertion failed: `assert_fn_ge_expr!(a_function, a_param, b_expr)`\n",
" a_function label: `i8::abs`,\n",
" a_param label: `a`,\n",
" a_param debug: `-1`,\n",
" b_expr label: `b`,\n",
" b_expr debug: `2`,\n",
" a: `1`,\n",
" b: `2`"
);
assert_eq!(actual, expect);