macro_rules! assert_fn_ok_ne_other_as_result {
    ($function:path, $a_input:expr, $b_input:expr $(,)?) => { ... };
}
Expand description

Assert one function ok() is not equal to another function ok().

  • When true, return Result Ok(()).

  • When true, return Result Err with a diagnostic message.

Examples

fn example_digit_to_string(i: i32) -> Result<String, String> {
    match i {
        0..=9 => Ok(format!("{}", i)),
        _ => Err(format!("{:?} is out of range", i)),
    }
}

let a: i32 = 1;
let b: i32 = 2;
let x = assert_fn_ok_ne_other_as_result!(example_digit_to_string, a, b);
//-> Ok(())
let actual = x.unwrap();
let expect = ();
assert_eq!(actual, expect);

let a: i32 = 1;
let b: i32 = 1;
let x = assert_fn_ok_ne_other_as_result!(example_digit_to_string, a, b);
//-> Err(…)
let actual = x.unwrap_err();
let expect = concat!(
    "assertion failed: `assert_fn_ok_ne_other!(function, left_input, right_input)`\n",
    "    function name: `example_digit_to_string`,\n",
    "  left input name: `a`,\n",
    " right input name: `b`,\n",
    "       left input: `1`,\n",
    "      right input: `1`,\n",
    "      left output: `\"1\"`,\n",
    "     right output: `\"1\"`"
);
assert_eq!(actual, expect);