expect

Macro expect 

Source
macro_rules! expect {
    ($var:ident = $rls:expr, $dgb:expr) => { ... };
    ($var:ident: $typ:ty = $rls:expr, $dgb:expr) => { ... };
}
Expand description

Macro to define different expected values for debug and release

This is useful when testing logic with differing expected results based on build.

Basically erogonomifies the following …

cfg_if! {
   if #[cfg(not(debug_assertions))] {
       let expected = 42; // release build value
   } else {
       let expected = 0; // debug build value
   }
}

with …

expect! { expected = 42, 0 }

§Features

  • lets you define both release and debug initialization values for expected variable
  • lets you optionally provide an explicit type when defining an expected variable

* release initialization value is defined first, followed by the debug value

§Examples

  • implicit type
// 42 is the expected value for release
// default is the expected value for debug
expect! { expected = 42, 0 }
  • explict type
// 42 is the expected value for release
// default is the expected value for debug
expect! { expected: usize = 42, Default::default() }