elidupree / live-prop-test

Fearlessly write both cheap and expensive runtime tests (contracts) for Rust functions.
Apache License 2.0
0 stars 0 forks source link

Improve failure messages for simple condition expressions #8

Open elidupree opened 4 years ago

elidupree commented 4 years ago

For example, #[live_prop_test(postcondition = "a == b")] should print out at least as much information as assert_eq!(a, b).

The expression a == b could be implicitly replaced by something like

{
  let __live_prop_test_left = a;
  let __live_prop_test_right = b;
  match __live_prop_test_left == __live_prop_test_right {
    true => Ok(())
    false => Err(format!("\n  left: {:?}\n  right: {:?}", __live_prop_test_left, __live_prop_test_right))
  }
}

The format expression there actually has to be a clever trick so it can have a fallback when the types do not implement Debug.

I'm thinking this should apply to inequality operators as well. Can this be generalized even further? I'm not sure.